Listing 2. Initial Version of Perl Program hello.pl
#!/usr/bin/perl -w
# -w warning on error
# CGI-BIN program to process Web forms-input data.
# POST method to extract parameter strings.
# Single value extracted
use strict;
use diagnostics;
use CGI_Lite;
# Create an instance of CGI_Lite
my $query = new CGI_Lite;
# Send an appropriate MIME header to the browser
print "Content-type: text/html\n\n";
# Send the beginning HTML
print "<HTML><Head><Title>Hello!</Title>\n";
print "</Head></Body>\n";
# Get the form data into a hash
my %FORM = $query->parse_form_data;
# Get the user's name from the hash
my $firstname = $FORM{"firstname"};
# Now that we have retrieved the username,
# we print it out
print "<P>Hello, $firstname</P>\n";
print "</Body></HTML>\n";
Copyright © 1994 - 2018 Linux Journal. All rights reserved.