So I currently have the below script which I can search 1 txt file. However I have 168 text files in the directory that I need it to look at. In the directory I have files that look like this 0-Mon.txt 1-Mon.txt 0-Tues.txt and etc. What I would like it to do is look at all the ones starting with 0, then 1 etc.
#!/usr/bin/perl
use strict;
use warnings;
use CGI ':standard';
print header,
start_html('Player Point Tracker'),
h1('Point Tracker'),
start_form,
body(''), p,
'Players Name: ',
textfield('name'), br,
submit('Search!'),
end_form, p,
hr;
my $search_term =param('name');
my $file = '18.txt';
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 18:00 server time $word had $count p
+oints.",p;
}
}
close ($FILE_HANDLE);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.