1 / 15

CGI programming using Perl

CGI programming using Perl. Sam Department of Computer Science and Engineering The Chinese University of Hong Kong. Content. Brief Introduction of Perl Useful Techniques CGI Example Favorite Links to Visit. Perl. Perl is a high-level programming language Advantages:

creola
Download Presentation

CGI programming using Perl

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CGI programming using Perl Sam Department of Computer Science and Engineering The Chinese University of Hong Kong

  2. Content Brief Introduction of Perl Useful Techniques CGI Example Favorite Links to Visit

  3. Perl Perl is a high-level programming language Advantages: rapid development (interpreted language) portable across many platforms (UNIX, Windows, etc) faster execution than shell scripts free and huge library of free modules and scripts

  4. Key language features and examples 1. Basic Regular Expressions (regex) Perl's regex often look like this: $name=~/piper/ That is saying "If 'piper' is inside $name, then True."

  5. Key language features and examples More Example: $_='My email address is <Robert@NetCat.co.uk>.'; /(<robert\@netcat.co.uk>)/i; print "Found it ! $1\n"; Output: Found it ! <Robert@NetCat.co.uk>

  6. Key language features and examples 2. Splitting Example: $_='Piper:PA-28:Archer:OO-ROB:Antwerp';@details=split /:/, $_, 3;foreach (@details) { print "$_\n"; } Output: Piper PA-28 Archer:OO-ROB:Antwerp

  7. Key language features and examples 3. File Operations Example: $stuff="c:\scripts\stuff.txt"; open STUFF, $stuff; while (<STUFF>) { print "Line number $. is : $_"; }

  8. Key language features and examples More Example: @ARGV="c:/scripts/out.txt"; $^I=".bk"; while (<>) { tr/A-Z/a-z/; print; }

  9. Key language features and examples 3. Associative Arrays @myarray Vs %myhash Index ValueKey Value 0 Spain ES Spain 1 Belgium BE Belgium 2 Germany DE Germany

  10. Key language features and examples More Example: %countries=('NL','The Netherlands','BE','Belgium','DE' ,'Germany','MC','Monaco','ES','Spain'); print "Enter the country code:"; chop ($find=<STDIN>); $find=~tr/a-z/A-Z/; print "$countries{$find} has the code $find\n";

  11. CGI Example

  12. HTML and Perl files read (STDIN, $login_raw, $ENV{'CONTENT_LENGTH'});%logindata=split (/[&=]/, $login_raw);foreach (keys %logindata){ $logindata{$_}=~s/%([\dA-Fa-f]{2})/chr(hex $1)/ge; $logindata{$_}=~s/\+/ /g;} $logid=$logindata{'login'};$passwd=$logindata{'password'};... print "Content-type: text/html\n\n";print "<html><body>\n";... <html><head>... </head> <body>... <form method="POST" action="/cgi-vc/login_2.pl"><input type="password" name="password">... </form></html>

  13. Favorite Links to Visit Perl tutorial: Robert's Perl Tutorial http://www.netcat.co.uk/rob/perl/win32perltut.html Ten Perl Myths http://www.perl.com/pub ActiveSate Tool Corp. http://www.activestate.com

  14. Favorite Links to Visit Perl Editor: Pete's Place http://www.petes-place.com/ Resources: CPAN Module documentation http://theoryx5.uwinnipeq.ca/CPAN/ Matt's Script Archive http://www.worldwidemart.com/scripts/

  15. The End

More Related