I have cut your script down (see below)

1) You don't need ARGV (and were using it wrongly); use $filename =
'C:\Perl\bin\folder\princess.txt'; instead.

2) You do need to open and cloae the file being read (INPUT, below)

3) You need double quotes around strings containing variables; single quotes
will do elsewhere.

4) Make use of the HTML-named procedures from CGI.pm.

Your problems did not arise from lack of understanding of modules!

 #!usr/perl/bin

 use CGI;
my $pattern = param('query');
 chop($pattern);
my $count =0;
my $filename = 'C:\Perl\bin\folder\princess.txt';

 print header()
    ,start_html
    ,h1( 'TheOutputs, ')
    ,p("Matches found : $pattern")
    ,br;

 open INPUT, "<$filename"; # open file for reading
 while (my $line = <INPUT>)
 {
    @words = split (/$pattern/, $line);
    $count += $#words;
 }
 close INPUT;

my $report = 'No matches found.';
 if ($count) {$report = "Total numbers of matches : $count"}

 print p($report),end_html;

[As a matter of logic, consider the split statement, and consider what it
returns if the pattern is at the beginning, or end, of the line. The logic
above will almost certainly give the wrong answer.]

Regards
- Roger -


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to