Cgipm - A Perl Library for Web Applications Cgi.pm...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Copyright Ellis Horowitz 2003- 2005 A Perl Library for Web Applications Cgi.pm
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright Ellis Horowitz 2003- 2005 Background • CGI.pm is a Perl5 CGI library created by Lincoln Stein – http://stein.cshl.org/~lstein/ – Latest is 2.94 (June 2003) at • http://search.cpan.org/author/LDS/CGI.pm-2.94/ – Available on Unix, Windows ( Included in ActivePerl) , Mac – Requires Perl 5.x • CGI.pm is used in the Deitel, et al book to demonstrate Perl programming
Background image of page 2
Copyright Ellis Horowitz 2003- 2005 Two modes – Function mode • In function mode, you import CGI functions #!/usr/usc/bin/perl use CGI qw/:standard/; print header(), start_html(-title=>’Wow’), h1(‘Wow!’), ’Look Ma, no hands!’, end_html(); • Use operator loads CGI.pm definitions and :standard functions • header() – generates Content-type: text/html • start_html() – generates <html><title> etc
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright Ellis Horowitz 2003- 2005 Two modes – Object mode • In object mode, you import no functions, but create CGI objects using the new() operator #!/usr/usc/bin/perl use CGI; $q = new CGI; print $q->header(), $q->start_html(-title=>’Wow’), $q->h1(‘Wow!’), ’Look Ma, no hands!’, $q->end_html();
Background image of page 4
Copyright Ellis Horowitz 2003- 2005 Example 1 – Plain Text #!/usr/usc/bin/perl use CGI qw/:standard/; print header('text/plain'), "Nothing to it!";
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright Ellis Horowitz 2003- 2005 Example 2 – Formatted Text #!/usr/usc/bin/perl use CGI ':standard'; print header('text/plain'); print "Jabberwock\n\n"; print "'Twas brillig, and the slithy toves\n"; print "Did gyre and gimbol in the wave.\n"; print "All mimsy were the borogroves,\n"; print "And the mome raths outgrabe. ...\n";
Background image of page 6
Copyright Ellis Horowitz 2003- 2005 Example 3 – Simpler Version #!/usr/usc/bin/perl use CGI ':standard'; $header = header('text/plain'); print <END_OF_TEXT; $header Jabberwock 'Twas brillig, and the slithy toves Did gyre and gimbol in the wave. All mimsy were the borogroves, And the mome raths outgrabe. ... END_OF_TEXT
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright Ellis Horowitz 2003- 2005 Star out 4 letter words #!/usr/usc/bin/perl use CGI ':standard'; $FILE = './speech.txt'; open (FILE,$FILE) || die "Can't open $FILE: $!\n"; print header('text/plain'); while () { s/\b(\w)\w{2}(\w)\b/$1**$2/g; print; } close FILE;
Background image of page 8
Copyright Ellis Horowitz 2003- 2005 Browser Output
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright Ellis Horowitz 2003- 2005 Example 5 – Print local time #!/usr/usc/bin/perl use CGI ':standard'; $current_time = localtime; print header, start_html('A Virtual Clock'), h1('A Virtual Clock'), "The current time is $current_time.", hr, end_html;
Background image of page 10
2005 Example 6 – Print local time again #!/usr/usc/bin/perl use CGI ':standard'; $current_time = localtime; print header, start_html('A Virtual Clock'); print <<END_OF_TEXT < H1>A Virtual Clock</H1> The current time is $current_time. END_OF_TEXT
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/24/2011 for the course CSCI 571 at USC.

Page1 / 40

Cgipm - A Perl Library for Web Applications Cgi.pm...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online