cgi programming using perl

Download CGI programming using Perl

Post on 13-Jan-2016

43 views

Category:

Documents

0 download

Embed Size (px)

DESCRIPTION

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: - PowerPoint PPT Presentation

TRANSCRIPT

  • CGI programming using PerlSam Department of Computer Science and EngineeringThe Chinese University of Hong Kong

  • ContentBrief Introduction of PerlUseful TechniquesCGI ExampleFavorite Links to Visit

  • 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

  • Key language features and examples1. Basic Regular Expressions (regex)

    Perl's regex often look like this:

    $name=~/piper/

    That is saying "If 'piper' is inside $name, then True."

  • Key language features and examplesMore Example:$_='My email address is .';

    /()/i;

    print "Found it ! $1\n";

    Output:Found it !

  • Key language features and examples2. SplittingExample:$_='Piper:PA-28:Archer:OO-ROB:Antwerp'; @details=split /:/, $_, 3; foreach (@details) { print "$_\n"; } Output:PiperPA-28Archer:OO-ROB:Antwerp

  • Key language features and examples3. File OperationsExample:$stuff="c:\scripts\stuff.txt";

    open STUFF, $stuff;

    while () { print "Line number $. is : $_";}

  • Key language features and examplesMore Example:@ARGV="c:/scripts/out.txt";

    $^I=".bk"; while () {tr/A-Z/a-z/; print; }

  • Key language features and examples3. Associative Arrays

    @myarray Vs%myhashIndex ValueKeyValue0 SpainESSpain1 BelgiumBEBelgium2 GermanyDEGermany

  • Key language features and examplesMore Example:%countries=('NL','The Netherlands','BE','Belgium','DE','Germany','MC','Monaco','ES','Spain');

    print "Enter the country code:";chop ($find=);

    $find=~tr/a-z/A-Z/;print "$countries{$find} has the code $find\n";

  • CGI Example

  • 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 "\n"; ...

  • Favorite Links to VisitPerl tutorial:Robert's Perl Tutorialhttp://www.netcat.co.uk/rob/perl/win32perltut.html

    Ten Perl Mythshttp://www.perl.com/pub

    ActiveSate Tool Corp.http://www.activestate.com

  • Favorite Links to VisitPerl Editor:Pete's Placehttp://www.petes-place.com/

    Resources:CPAN Module documentationhttp://theoryx5.uwinnipeq.ca/CPAN/

    Matt's Script Archivehttp://www.worldwidemart.com/scripts/

  • The End