CECS 5100Survey of Educational Computer Languages
Fall 2002
|
||||||||||||
|
Need a free MP3 Player to listen to these clips ?
#!/usr/bin/perl
# Print out a content-type for HTTP/1.0 compatibility
print "Content-type: text/html\n\n";
print "<html><body>";
# Determine where the info is coming from
if ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} else {
$buffer = $ENV{'QUERY_STRING'};
}
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
# Uncomment for debugging purposes
print "Setting $name to $value<P>";
$FORM{$name} = $value;
}
#!/usr/bin/perl
# Print out a content-type for HTTP/1.0 compatibility
print "Content-type: text/html\n\n";
# Determine where the info is coming from
if ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} else {
$buffer = $ENV{'QUERY_STRING'};
}
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
# Uncomment for debugging purposes
#print "Setting $name to '$value'<P>";
$FORM{$name} = $value;
}
print "<html><body>";
print "<h2>Example use of Hash from Form</h2>";
print "<pre>";
$fullname = join (" ",$FORM{'first'},$FORM{'MI'},$FORM{'surname'});
print "Name: $fullname<p>";
print "</pre>";
print "
<form action=\"http://saturn.cecs.unt.edu/cgi-bin/gjones/greg.cgi\" method=\"POST\">
<P><b>Please enter your name:</b>
First name: <INPUT NAME=\"first\" TYPE=\"TEXT\" SIZE=\"12\" MAXLENGTH=\"20\">
</form>
";
print "</body></html>";
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html><body>\n";
# You store the string into the hash array $FORM using the index value of 'test'.
$FORM{'test'} = "Dr Greg Jones University of North Texas";
# The first split uses assigned variables to place the values from the string
($a, $b, $c, $d, $e, $f, $g) = split (" ", $FORM{'test'});
# this print statement prints out the assigned variable set above
print "'$a', '$b', '$c', '$d', '$e', '$f', '$g' <p>\n";
# Instead of assigning each variable as above,
# you use the @tests method to place them in their own HASH array
@tests = split (" ", $FORM{'test'});
# use the foreach loop to walk through each assigned values in the hash array tests
foreach $test (@tests) {
print "'$test', ";
}
print "<p>\n";
Copyright 2002, Dr. James G Jones |
||||||||||||