|
Posted by John W. Krahn on October 27, 2005, 11:05 pm
Please log in for more thread options
mac wrote:
> Hi
Since you are not using modules or asking a question about modules what made
you decide that comp.lang.perl.modules was the correct newsgroup for this?
> I have this code but it does not seem to list non-html files.
What error or warning messages do you get? What does it "seem to list"?
> Could anyone point me in the right direction.
>
>
>
> #!/usr/bin/perl
Since this is a CGI program you should use taint mode and you should also
enable warnings and strict.
#!/usr/bin/perl -T
use warnings;
use strict;
> print "Content-type: text/html\n\n";
> # Define Variables
> $basedir = '../';
> $baseurl = 'http://www.mywebsite.co.uk/';
> @files = (*.zip');
^^
You are missing a quote.
> $title = "My Web Site";
>
> # Get Files To Search Through
> &get_files;
Why are you using a subroutine for code that will only run once? Why are you
using Perl4 style subroutine calls?
> # Print Results of Search
> &return_html;
>
> sub get_files {
>
> chdir($basedir);
You should verify that chdir() worked correctly.
> foreach $file (@files) {
> $ls = `ls $file`;
Is the ls command available? Why not use perl's built-in opendir/readdir or
glob functions?
> @ls = split(/\s+/,$ls);
What if your file names contain whitespace? Why not just use backticks in
list context?
> foreach $temp_file (@ls) {
> if (-d $file) {
> $filename = "$file$temp_file";
You are missing a directory separator between $file and $temp_file.
> if (-T $filename) {
> push(@FILES,$filename);
> }
> }
> elsif (-T $temp_file) {
> push(@FILES,$temp_file);
> }
> }
> }
> }
>
> sub return_html {
> print "<html>\n";
> print "<head>\n";
> print "<title>Directory</title>\n";
> print "</head>\n";
> print "<body>\n";
>
> print "Contents of folder:<p>\n";
>
> foreach $FILE (@FILES) {
> print "<a href=\"$baseurl$FILE\">$FILE</a></p>\n";
> }
>
> print "</body>";
> print "\n</html>";
>
> }
John
--
use Perl;
program
fulfillment
|