Rather than repeat what the others have already said, i'll am going to post a working solution
for you play with. Sometimes it helps to have a working example first:
use strict;
use warnings;
use CGI qw(:standard);
my %snailmail = (
Pam => 'pammy@foo.com',
Sal => 'sally@bar.com',
Tom => 'tom@there.com',
);
print header,start_html('find it');
print start_form,
p('Name: ', textfield('name')),
p('Fetch: ', popup_menu('search',[qw(Exact All)])),
p(submit('fetch')),
end_form,
;
if (param('fetch')) {
if (param('search') eq 'Exact') {
my $name = param('name');
my $email = $snailmail{$name};
if ($email) {
print p("$name: $email");
}
else {
print p("'$name' not found in directory");
}
}
else {
print p("$_: $snailmail{$_}") for sort keys %snailmail;
}
}
Feel free to ask any questions about this code. :)
|