|
| |
CGI Scripts
|
Web Hosting Services |
search_file.plThis script will take the information entered on the form, parse it, open names_file.txt and search for a match. #!/usr/bin/perl#search_file.plread(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 Headerprint "<html>\n";print "<head><title>Display File Contents</title></head>\n";print "<body>\n";print "<h4>This script displays the contents of names_file.txt.<br>No names means your search returned no results.</h4>\n";foreach $line (@array){if ($line =~ /$search/){($last,$first)=split(/\|/,$line);print "Your search returned: $first $last<br>\n";}}print "</body>\n";print "</html>\n";names_file.txtIf you haven't completed the previous exercises, copy this file to notepad. Save it in the cgi-bin directory as names_file.txt. Bunyan|PaulSimpson|BartAnderson|PamelaBush|GeorgeNote: If the scripts don't work: |
Create a Website with CMS
|
| Net Success 2000 Plus Inc PO Box 1508 Somerset, KY 42502 Copyright 2000 - 2007 Net Success 2000 Plus Inc Last Modified: January 16, 2008 |