#!/usr/local/bin/perl ############################################################################ # order2: Take orders for ice cream shop # use Perl for the form field validations ############################################################################ use CGI "param"; $fname = param('fullname'); $addr = param('addr'); @choice = param('ice'); print "Content-type: text/html \n"; print "\n"; &validate(); # call validate subroutine open (ORDERFILE, ">> ../../data/order.file") || print "Cannot open file - $!"; flock (ORDERFILE, 2); # get exclusive control $addr2 = $addr; $addr2 =~ s/\r\n/__/g; # substitute newlines with __ $rec = join(":",($fname,$addr2,$choice[0]) ); print ORDERFILE "$rec\n"; flock (ORDERFILE, 8); # release exclusive control close(ORDERFILE); print " Thank You

Thank you for your order

The order will be processed for:

$fname

$addr

$choice[0] "; exit(0); ############################################################################# # validate: validate entry fields ############################################################################# sub validate { $errorMsg = ''; if ($fname eq '') { $errorMsg .= '- Please enter a fullname!!!
'; } if ($addr eq '') { $errorMsg .= '- Please enter an address!!!
'; } if ($choice[0] eq '') { $errorMsg .= '- Please enter ice Cream flavor!!!
'; } if ($errorMsg ne '') { print "ERROR!
$errorMsg"; exit(0); } }