Could you guys take a peek at my code?
I would appreciate any suggestions on bugs, bad syntax,etc.
As you can tell, it's just a script that retrieves records from a flat-file database.
THANKS
#!usr/local/bin/perl -w
use CGI;
$query =new CGI;
$guest_file = "guests.txt";
&print_page_start;
if ($query->param()) {
$search_name = $query->param('search_name');
eval {
open (GUESTS, "< $guest_file") or
die "Can't open $guest_file: $!";
while (<GUESTS>) {
chomp;
($name, $email, $comments) = split /::/;
if ($name =~ /$search_name/i {
print "$name<BR>\n$email<BR>\n$comments<BR>\n<HR>\n";
}
}
}
}
else {
print "<FORM>\n";
print "<INPUT TYPE=\"text\" NAME=\"search_name\"><BR>\n";
print "<INPUT TYPE=\"submit\">\n";
print "</FORM>\n";
}
chomp $@;
if ($@) {
print "ERROR: $@<BR>\n";
}
&print_page_end;
sub print_page_start {
print $query->header;
print "<HTML>\n<HEAD>\n<TITLE>Search for Records</TITLE>\n";
print "</HEAD>\n<BODY>\n";
print "<H1>Search for Records</H1>\n;
}
sub print_page_end {
print "</BODY>\n</HTML>\n";
}
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.