N
Nick
I have a partial perl script that i want to understand and then be able
to change. It simply searches a text file for text and print that text
to a web page. I want to understand the array and be able to add
multiple more lines.
At the moment, it has two fields (surname and forename), i need to
expand that to around 6 or 7 fields.
Ultimately, i want to be able to search a text file for specific text
and have it output all matches (the complete line) to a web page.
Below is what i have so far:
#!/usr/bin/perl -w
use CGI;
use CGI::Carp qw(fatalsToBrowser); # Hook errors to browser
#search_file.pl
read(STDIN, $buffer,$ENV{'CONTENT_LENGTH'});
$buffer =~ tr/+/ /;
$buffer =~ s/\r/ /g;
$buffer =~ s/\n/ /g;
@pairs = split(/&/,$buffer);
foreach $pair(@pairs){
($key,$value)=split(/=/,$pair);
$formdata{$key}.="$value";
}
$search=$formdata{'search'};
open(INFO, "names_file.txt"); # Open db for reading
@array=<INFO>;
close (INFO);
print "Content-type:text/html\n\n"; #Content Header
print <<End_of_head;
<html>
<head><title>Display File Contents</title></head>
<body>
<h4>This script displays the contents of names_file.txt.</h4>
End_of_head
foreach $line (@array){
if ($line =~ /$search/){
($last,$first)=split(/\|/,$line);
print <<End_of_line;
Your search returned: $first $last<br>
End_of_line
}
}
print <<End_of_Doc;
</body>
</html>
End_of_Doc
Any help much appreciated.
Nick
to change. It simply searches a text file for text and print that text
to a web page. I want to understand the array and be able to add
multiple more lines.
At the moment, it has two fields (surname and forename), i need to
expand that to around 6 or 7 fields.
Ultimately, i want to be able to search a text file for specific text
and have it output all matches (the complete line) to a web page.
Below is what i have so far:
#!/usr/bin/perl -w
use CGI;
use CGI::Carp qw(fatalsToBrowser); # Hook errors to browser
#search_file.pl
read(STDIN, $buffer,$ENV{'CONTENT_LENGTH'});
$buffer =~ tr/+/ /;
$buffer =~ s/\r/ /g;
$buffer =~ s/\n/ /g;
@pairs = split(/&/,$buffer);
foreach $pair(@pairs){
($key,$value)=split(/=/,$pair);
$formdata{$key}.="$value";
}
$search=$formdata{'search'};
open(INFO, "names_file.txt"); # Open db for reading
@array=<INFO>;
close (INFO);
print "Content-type:text/html\n\n"; #Content Header
print <<End_of_head;
<html>
<head><title>Display File Contents</title></head>
<body>
<h4>This script displays the contents of names_file.txt.</h4>
End_of_head
foreach $line (@array){
if ($line =~ /$search/){
($last,$first)=split(/\|/,$line);
print <<End_of_line;
Your search returned: $first $last<br>
End_of_line
}
}
print <<End_of_Doc;
</body>
</html>
End_of_Doc
Any help much appreciated.
Nick