in reply to Re: cgi search all txt files in a directory
in thread cgi search all txt files in a directory

Thanks for you reply, My question though are where do I specify the path to the file and also it looks like that is only going to open files with the name "0" or "1" and I need it to open "1-Mon.txt" or "22-Fri.txt" Thanks!
  • Comment on Re^2: cgi search all txt files in a directory

Replies are listed 'Best First'.
Re^3: cgi search all txt files in a directory
by perlpie (Beadle) on Sep 23, 2010 at 03:17 UTC

    It will open files that start with $digit. The star after $digit is a glob. For example, when $digit is 1, then you'll get all files starting with 1. If you need to put some more path around that, go ahead. For example:

    </path/to/some/directory/$digit*>
      Ok I got it working I would like to change up a little of what I am doing, Instead of how if is currently printing the data I would like to to print it into a table Something that looks liek this
      0:00 1:00 2:00 3:00 ... 23:00 aug 1 data from text files here aug 2 data from text files here aug 3 data from text files here aug 4 data from text files here
      again here is my current code
      #!/usr/bin/perl use strict; use warnings; use CGI ':standard'; print header, start_html('Player Point Tracker'), h1('W51 Point Tracker'), start_form, body('The website is also case sensitive and may take awhile to se +arch, It will be looking though alot of data.'), p, 'Players Name: ', textfield('name'), br, submit('Search!'), end_form, p, hr; my $search_term =param('name'); print "$search_term", p; for my $digit (0 .. 9) { for my $file (<$digit*>) { open (my $FILE_HANDLE, '<', $file) || die "Can't open $file: $ +! \n"; while (<$FILE_HANDLE>) { chomp; my ($word, $count) = split / /, $_; if ($word =~ /^$search_term$/) { print "At $file $word had $count points.", p; #print "$file"; } } close ($FILE_HANDLE); } }
      Thanks you have been really helpful, but when doing this </path/to/some/directory/$digit*> I get the following errors
      Bareword found where operator expected at pointsnew.cgi line 24, near +"/var/www" (Missing operator before www?) "my" variable $file masks earlier declaration in same scope at pointsn +ew.cgi line 25. syntax error at pointsnew.cgi line 24, near "/var/www" syntax error at pointsnew.cgi line 37, near "}" Execution of pointsnew.cgi aborted due to compilation errors.