----------------------------------------------------------------------------- YOUR FIRST PERL/CGI WEB PROGRAMMING ASSIGNMENT ----------------------------------------------------------------------------- 1. Study the Listing 2.2 Complete Source of the Interest Program on pages 34 and 35 of Hour 2 of the Greg Perry textbook. We will compare that program to the cyl.cgi volume of a cylinder program that we did today in the hands-on lab class. Below, you will see the cyl.cgi program modified so that it is NOT a web based application, but a program anyone uses from the chaos or DOS or ICEMAN or COBRA or VIPER command line, or wherever they have PERL. 2. Here is cyl.cgi transformed into cyl.p, so that it is not web-based, but is like the Interest program on pages 34 and 35 of SAMS Teach Yourself Perl in 24 Hours by Greg Perry. #!/usr/bin/perl -w print "\nPlease enter the radius of the cylinder: "; $radius = ; chomp $radius; print "\n Enter the height of the cylinder: "; $height = ; chomp $height; $area = 3.14159 * ($radius ** 2) * $height; print "\n\nA cylinder with height $height and radius $radius " . "has area: $area \n\n"; ------------------------------------------------------------ Sample output of the above program (The file is named cyl.p) ------------------------------------------------------------ bebop:~/web/cgi-bin$ perl cyl.p Please enter the radius of the cylinder: 1 Enter the height of the cylinder: 10 A cylinder with height 10 and radius 1 has area: 31.4159 bebop:~/web/cgi-bin$ perl cyl.p Please enter the radius of the cylinder: 10 Enter the height of the cylinder: 2 A cylinder with height 2 and radius 10 has area: 628.318 3. Compare the above cyl.p program to cyl.cgi that we wrote and implemented in today's lab (along with the HTML page and FORM consisting of two Text Boxes and two buttons (Submit and Reset). <--- file name is area.html in web folder Calculate area of a cylinder using PERL and CGI

Area of a cylinder calculator and PERL/CGI demo

Radius of cylinder:

Height of cylinder:

------------------- area.html has permissions chmod 644 area.html ------------------- --------------------------------------------- URL for above: http://student.cns.uni.edu/~venkman/area.html --------------------------------------------- Do the View Source command at that URL to see the HTML code online. I will add a link to the ~venkman/area.html code from ~jacobson/c088.html Perl course web page. 4. Here is the cyl.cgi code we wrote today in hand-on class, or else it is a close approximation to what we wrote. Note that the cyl.cgi file would be inside the cgi-bin folder, and cyl.cgi would have permissions 755, via chmod 755 cyl.cgi. ----------------- cyl.cgi with permissions 755 ------------------------------------------------------------------------ #!/usr/bin/perl -w use CGI ':standard'; print "Content-type: text/html\n\n"; $r = param('radius'); $h = param('height'); $area = 3.14159 * $r * $r * $h; print << "END-OF-HTML code"; # <---- See page 234 of Castro book # This is a nifty shortcut # called a here document... Area of the cylinder via Perl script

Area of cylinder via Perl script cyl.cgi

For cylinder with radius $r and height $h, the area is: $area

END-OF-HTML code ----------------------------------------------------------------------- "Perl has a nifty shortcut, cyptically called a here document, that can save you a lot of typing (and tedium). Page 234 of Elizabeth Castro ----------------------------------------------------------------------- # The above Perl script did not need any \n and didn't need a TON of "" # and ; and . and print statements, because of the HERE document # technique that was used. print "END-OF-HTML code"; <---- Signals start of HERE document END-OF-HTML code <---- The HERE document label 5. Make the Interest Calculator from pages 34-35 of Greg Perry into a web based and FORM submitted and PERL/CGI processed application. If you study the above non-web based cylinder area calculator and compare it to the web and FORM based cylinder area calculator, you will have a solid foundation for taking on the task of making the Interest Calculator program into a web/FORM/PERL/CGI based application. Send the URL for your form via email to jacobson @ cns.uni.edu or to jacobson @ uni.edu when you are done with your script. I will try it out online to make sure it works okay, but I want a printout of the Perl program next week too. Type printers at the cowboy prompt to learn how to print from cowboy. (bebop, spike, julia, jet or ) ----------------------------- enscript -2r -dwrt112 cyl.cgi would print it on the WRT 112 ----------------------------- laser printer, in rotated or landscape mode, with two columns of print per page.