#!/usr/bin/perl use CGI; #change this to the full pathname to the bottom of the dir structure: my $dir = "."; print "Content-type: text/html\n\n"; my $cgiin = CGI->new; my $letter = $cgiin->param('letter'); if (($letter eq "") && ($ARGV[0] =~ /[\w|\.]/)) { $letter = $ARGV[0]; print "Running from the command line, looking for things that start with $letter\n"; } if ($letter !~ /[\w|\.]/) { print "

Please specify a valid letter

"; die "Invalid letter given"; } my @errors; #my $givendir = $ARGV[0]; #if ($givendir eq "") { $givendir = "."; #} opendir('FLIST', "."); my @dirs = readdir('FLIST'); closedir('FLIST'); while(@dirs) { my $workdir = shift(@dirs); while(($workdir eq '.') || ($workdir eq '..')) { $workdir = shift(@dirs); } opendir('CURDIR', "$workdir"); my @prefilelist = readdir('CURDIR'); closedir('CURDIR'); my @filelist; while(@prefilelist) { my $workline = shift(@prefilelist); if (($workline ne '.') && ($workline ne '..')) { push(@filelist, "$workline"); } } my $numfiles = @filelist; if ($numfiles != 1) { push(@errors, "in $workdir: expected 1 file, found $numfiles"); } else { if (($workdir =~ /^($letter)/i) || (($letter eq '.') && ($workdir =~ /^\d/))) { print "$workdir
\n"; } else { print "Not matching $workdir because it doesn't start with a $letter
\n"; } } } #my $numerrors = @errors; #if ($numerrors != 0) { # print "WARNING: $numerrors reported errors:\n"; #} #while(@errors) { # my $errorline = shift(@errors); # print "$errorline\n"; #}