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

# File Name: astmplast5.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("

Today we are debugging.

\n\n"); # print("

\n"); # print("$query



"); # # The material below was written by Steve Verrill, 10/95 -- 11/95 # #Try to parse $query. & separates fields. + separates multiple items in a field. @fields = split(/&/, $query); # print ("@fields

"); # foreach $temp (@fields) { # print ("$temp
"); # } # print("

"); $errflag = 0; # # Number of reduction factors # $fields[0] =~ s/[^\d]//g; $numred = $fields[0]; # # The reduction factors # # # pluses in the original input create %2B's. Handle. # $fields[1] =~ s/%2B/\+/g; # # get rid of everything other than minus signs, plus signs, decimals, # and digits # $fields[1] =~ s/[^-\+\.\d]//g; # # get rid of leading pluses # $fields[1] =~ s/^[\+]+//; # # get rid of trailing pluses # $fields[1] =~ s/[\+]+$//; @reds = split(/[\+]+/, $fields[1]); $numred2 = @reds; if ($numred2 != $numred) { print("
The number of reduction factors supplied, $numred2, does not equal the number chosen, $numred. Please correct the data entry form.

"); $errflag = 1; } # # Coefficients of variation # $fields[2] =~ s/[^\d]//g; $numcv = $fields[2]; # # pluses in the original input create %2B's. Handle. # $fields[3] =~ s/%2B/\+/g; # # get rid of everything other than minus signs, plus signs, decimals, # and digits # $fields[3] =~ s/[^-\+\.\d]//g; # # get rid of leading pluses # $fields[3] =~ s/^[\+]+//; # # get rid of trailing pluses # $fields[3] =~ s/[\+]+$//; @cvs = split(/[\+]+/, $fields[3]); $numcv2 = @cvs; if ($numcv2 != $numcv) { print("
The number of cvs supplied, $numcv2, does not equal the number chosen, $numcv. Please correct the data entry form.

"); $errflag = 1; } foreach $temp (@cvs) { if ($temp == 0) { print("
Coefficients of variation equal to 0 are not permitted. Please correct the data entry form.

"); $errflag = 1; } } # # number of specimens used to estimate mu1 # $fields[4] =~ s/n1=//; $fields[4] =~ s/[^\d]//g; $n1 = $fields[4]; if ($n1 < 1 || $n1 > 200) { print("
The number of specimens was less than 1 or greater than 200. Please correct the form.

"); $errflag = 1; } # # number of specimens used to estimate mu2 # $fields[5] =~ s/n2=//; $fields[5] =~ s/[^\d]//g; $n2 = $fields[5]; if ($n2 < 1 || $n2 > 200) { print("
The number of specimens was less than 1 or greater than 200. Please correct the form.

"); $errflag = 1; } $fields[6] =~ s/results=//; if ($fields[6] eq "") { $fields[6] = "delme"; } @list = ("/export/home/ftp/pub/data/",$fields[6]); $results = join("",@list); if ($errflag != 1) { @proglist = ("astmplast5","$numred","@reds","$numcv","@cvs","$n1", "$n2","$results","$fields[6]"); system(@proglist); } # print("

"); # print("@fields
"); } 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; }