#!/usr/local/bin/perl
# This was copied from pages 342 and 343 of the book
# Build a Web Site.

# File Name: dryingsp.pl

local($request_method,$content_length,$query_string);

#
#   This assignment ensures that there are not problems in
#   mixing fortran output with perl output.
#

$| = 1;

#Grab REQUEST_METHOD, CONTENT_LENGTH, and QUERY_STRING

$request_method = $ENV{'REQUEST_METHOD'};
$content_length = $ENV{'CONTENT_LENGTH'};
$query_string = $ENV{'QUERY_STRING'};

#Check whether this was a PUT or a POST

if (($request_method eq 'POST') || ($request_method eq 'PUT')) {

#If so, read the appropriate number of bytes from STDIN

   read(STDIN, $query, $content_length);

#echo these bytes 

   print("Content-Type: text/html\n\n");
#   print("

The data received was:

\n\n"); # print("

\n"); # print("$query


"); # # The material below was written by Steve Verrill, 6/96 # #Try to parse $query. & separates fields. + separates multiple items in a field. @fields = split(/&/, $query); # foreach $temp (@fields) { # print ("$temp
"); # } # # Thickness # $thick = $fields[1]; # # get rid of thick= # $thick =~ s/thick=//; # # Botanical name # $botname = $fields[0]; # # get rid of sp= # $botname =~ s/sp=//; # # blanks in the original lead to +'s # # # get rid of leading pluses # $botname =~ s/^[\+]+//; # # get rid of trailing pluses # $botname =~ s/[\+]+$//; # # replace remaining +'s with blanks # $botname =~ s/\+/ /g; # # translate upper case to lower case # $botnorig = $botname; $botname =~ tr/A-Z/a-z/; # print ("$botname
"); # # Data file # $drydata = ("./drying.dat"); if (open(DATA,$drydata)) { $match = 0; $line = ; while ($line ne "") { @fields = split(/&/, $line); # # $fields[0] is the botanical name. $fields[1] is the specific gravity. # # # get rid of leading blanks # $fields[0] =~ s/^[ ]+//; $fields[1] =~ s/^[ ]+//; # # get rid of trailing blanks # $fields[0] =~ s/[ ]+$//; $fields[1] =~ s/[ ]+$//; # # translate upper case to lower case # $fields[0] =~ tr/A-Z/a-z/; # print("$fields[0]
"); if ($botname eq $fields[0]) { $match = 1; $sub1 = substr($botname,0,1); $sub1 =~ tr/a-z/A-Z/; $sub2 = substr($botname,1,length($botname)-1); @list = ($sub1,$sub2); $newname = join("",@list); print("Return to Drying Program home page.


"); print("$newname

"); $sg = $fields[1]; print("The specific gravity is $sg.
"); if ($thick == 2538) { print("The thickness is from 25 to 38 mm.

"); @proglist = ("drying","$sg","$thick"); system(@proglist); } elsif ($thick == 50) { print("The thickness is 50 mm.

"); @proglist = ("drying","$sg","$thick"); system(@proglist); } else { print("No thickness was specified. Please"); print(" try again."); } print("



For further information, please contact Steve Verrill at steve\@www1.fpl.fs.fed.us or 608-231-9375.
"); print("Last modified on 4\/15\/01."); } $line = ; } if ($match == 0) { print("

WWW Drying Schedule Computer Program



"); print("There was no exact match between the name that you submitted and a name in the data file. Would you like to choose a name from the data file?

"); print(""); print("

For further information, please contact Steve Verrill at steve\@www1.fpl.fs.fed.us or 608-231-9375.
Last modified on 4/15/01."); } } else { print("
The drying data file name is not valid. Please contact Steve Verrill at steve\@www1.fpl.fs.fed.us or 608-231-9375.
Last modified on 4/15/01."); } } elsif ($request_method eq 'GET') { #If so, the data is in QUERY_STRING $query = $query_string; } else { #Otherwise, print an error print("Content-Type: text/html\n\n"); print("

Error: Unacceptable Method

\n\n"); print("
\n"); print("This script does not support the $ENV{'REQUEST_METHOD'}\n"); print("method for submitting forms. Please use the POST method.\n"); exit; }