1 #! /usr/local/bin/perl -w 2 3 ############################################################################# 4 # 5 # File: fill-out-form.pl 6 # 7 # Input: fill-out-form0.html 8 # (variables address, phone, topping) 9 # 10 # Output: HTML version of pizza order 11 # 12 # Description: Creates a pizza order from the information obtained from 13 # the pizza order form. 14 # 15 # 16 ############################################################################# 17 # 18 # Initialization 19 # 20 ############################################################################# 21 22 $EOL = "\015\012"; 23 $HTMLFILE = 'fill-out-form0.html'; # HTML doc with form 24 $HOSTPATH = 'http://www.npac.syr.edu/projects/tutorials/CGI/examples/basic'; 25 26 ############################################################################# 27 # 28 # Library Routines 29 # 30 ############################################################################# 31 32 require "ReadParse.pl" || die "error loading ReadParse.pl\n"; 33 34 ############################################################################# 35 # 36 # Main Routines 37 # 38 ############################################################################# 39 40 ReadEntry() && 41 PrintResult(); 42 43 ############################################################################## 44 # 45 # Input 46 # 47 ############################################################################## 48 49 sub ReadEntry { 50 my (%in); 51 # ReadParse returns an associative array of key-value pairs: 52 %in = ReadParse(); 53 $ADDRESS = $in{'address'}; 54 $PHONE = $in{'phone'}; 55 $TOPPING = $in{'topping'}; 56 return 1; 57 } 58 59 ############################################################################# 60 # 61 # Output 62 # 63 ############################################################################# 64 65 sub println { 66 print "@_$EOL"; 67 } 68 69 sub PrintResult { 70 println 'Content-type: text/html'; 71 println ''; 72 73 println '<HTML>'; 74 println '<HEAD>'; 75 println '<TITLE>CGI Example: Pizza</TITLE>'; 76 println '</HEAD>'; 77 println '<BODY BGCOLOR="#ffffff">'; 78 println '<H1>Pizza Order</H1>'; 79 80 println "<H3>$TOPPING pizza</H3>"; 81 82 println "Deliver to <B>$ADDRESS</B> <P>"; 83 println "Telephone: <B>$PHONE</B> <P>"; 84 85 $date = `date`; chomp($date); 86 println "Order came in at $date"; 87 88 println '<P><HR><P>Return to'; 89 println qq{<A HREF="$HOSTPATH/$HTMLFILE">HTML form</A>}; 90 91 println '</BODY>'; 92 println '</HTML>'; 93 return 1; 94 } 95