|
Kaye and Geoff's web page documentation
Perl script to search a defined file for a wordThe following Perl code outputs each line of a file (up to a maximum of 19) which contains a defined word. The first block of code gets the information passed from the form: the file name and the word. Then the code outputs the HTML for the start of the page which will be returned. Then there is some error checking to ensure that the file is readable and thst the word contains something other than whitespace. Each line is read in turn and checked to see if it contains the word ( $line =~ /$word/) can be read as 'if line contains the word then...'). Each line which matches is counted and output to standard output, so becomes part of the returned web page. When all lines have been processed the HTML is completed.
';
#
# check that the file exists and can be read
# ensure that there is something realistic to search for
#
$ok = '1';
unless (-r $file) { $ok = '0'; }
($word, $discard) = split (/\s+/, $word);
unless ($word =~ /\S/) { $ok = '0'; }
#
# look for the word
#
$n = 0;
if ($ok)
{
open (FILE, "$file");
while ($line = ';
print '';
exit; |
|
Top Close |