box-o-sand/PracticingPerl/web/html/cgi-bin/query.cgi

36 lines
604 B
Perl
Executable File

#!/usr/bin/env perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw(carpout fatalsToBrowser);
BEGIN {
use CGI::Carp qw(carpout);
open(LOG, ">>/home/me/tmp/mycgi-log") or
die("Unable to open mycgi-log: $!\n");
carpout(*LOG);
}
sub main {
my $query = CGI->new();
print $query->header(-content_type => 'text/plain');
my $search = $query->param('q');
if (!$search eq undef) {
printf("You searched for: %s\n", $query->escapeHTML($search));
} else {
printf("Invalid search? You must provide a 'q' argument.\n");
}
}
main();
1;
__END__