cgi programming using perl
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 PresentationTRANSCRIPT
![Page 1: CGI programming using Perl](https://reader030.vdocuments.us/reader030/viewer/2022033017/568146b7550346895db3df8f/html5/thumbnails/1.jpg)
CGI programming using Perl
Sam Department of Computer Science and Engineering
The Chinese University of Hong Kong
![Page 2: CGI programming using Perl](https://reader030.vdocuments.us/reader030/viewer/2022033017/568146b7550346895db3df8f/html5/thumbnails/2.jpg)
Content
Brief Introduction of Perl
Useful Techniques
CGI Example
Favorite Links to Visit
![Page 3: CGI programming using Perl](https://reader030.vdocuments.us/reader030/viewer/2022033017/568146b7550346895db3df8f/html5/thumbnails/3.jpg)
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
![Page 4: CGI programming using Perl](https://reader030.vdocuments.us/reader030/viewer/2022033017/568146b7550346895db3df8f/html5/thumbnails/4.jpg)
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."
![Page 5: CGI programming using Perl](https://reader030.vdocuments.us/reader030/viewer/2022033017/568146b7550346895db3df8f/html5/thumbnails/5.jpg)
Key language features and examplesMore Example:
$_='My email address is <[email protected]>.';
/(<robert\@netcat.co.uk>)/i;
print "Found it ! $1\n";
Output:
Found it ! <[email protected]>
![Page 6: CGI programming using Perl](https://reader030.vdocuments.us/reader030/viewer/2022033017/568146b7550346895db3df8f/html5/thumbnails/6.jpg)
Key language features and examples2. SplittingExample:
$_='Piper:PA-28:Archer:OO-ROB:Antwerp';@details=split /:/, $_, 3;foreach (@details) { print "$_\n"; }
Output:
Piper
PA-28
Archer:OO-ROB:Antwerp
![Page 7: CGI programming using Perl](https://reader030.vdocuments.us/reader030/viewer/2022033017/568146b7550346895db3df8f/html5/thumbnails/7.jpg)
Key language features and examples
3. File OperationsExample:
$stuff="c:\scripts\stuff.txt";
open STUFF, $stuff;
while (<STUFF>) {
print "Line number $. is : $_";
}
![Page 8: CGI programming using Perl](https://reader030.vdocuments.us/reader030/viewer/2022033017/568146b7550346895db3df8f/html5/thumbnails/8.jpg)
Key language features and examples
More Example:
@ARGV="c:/scripts/out.txt";
$^I=".bk";
while (<>) {
tr/A-Z/a-z/;
print;
}
![Page 9: CGI programming using Perl](https://reader030.vdocuments.us/reader030/viewer/2022033017/568146b7550346895db3df8f/html5/thumbnails/9.jpg)
Key language features and examples
3. Associative Arrays
@myarray Vs %myhash
Index Value Key Value
0 Spain ES Spain
1 Belgium BE Belgium
2 Germany DE Germany
![Page 10: CGI programming using Perl](https://reader030.vdocuments.us/reader030/viewer/2022033017/568146b7550346895db3df8f/html5/thumbnails/10.jpg)
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";
![Page 11: CGI programming using Perl](https://reader030.vdocuments.us/reader030/viewer/2022033017/568146b7550346895db3df8f/html5/thumbnails/11.jpg)
CGI Example
Network
1. Request server/http://pc89075.cse.cuhk.edu/
vc_index.html
Web Server(Web Professional)
Oracle 8
Database
Documents
Disk
Scripts
HTML formvc_ index.html
.... ....
Querytemplate+Code
login.pl
Learner/browser
2. Web Page vc_index.html
3. Action="login.pl "
/input login data4. Result Page
formrequestedby learner
2
passing CGI strings toscript and activate it3
query the databaseand get the results
change the results to HTML format
4
![Page 12: CGI programming using Perl](https://reader030.vdocuments.us/reader030/viewer/2022033017/568146b7550346895db3df8f/html5/thumbnails/12.jpg)
HTML and Perl files<html><head>... </head> <body>...
<form method="POST" action="/cgi-vc/login_2.pl"><input type="password" name="password">... </form></html>
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";...
![Page 13: CGI programming using Perl](https://reader030.vdocuments.us/reader030/viewer/2022033017/568146b7550346895db3df8f/html5/thumbnails/13.jpg)
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
![Page 14: CGI programming using Perl](https://reader030.vdocuments.us/reader030/viewer/2022033017/568146b7550346895db3df8f/html5/thumbnails/14.jpg)
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/
![Page 15: CGI programming using Perl](https://reader030.vdocuments.us/reader030/viewer/2022033017/568146b7550346895db3df8f/html5/thumbnails/15.jpg)
The End