# Code snippet for Web Programming at 2012/10/29, # slide at http://zoro.ee.ncku.edu.tw/swd2012/res/06-cgi.pdf ################################################################################ # index.html


################################################################################ # do.cgi #!/usr/bin/perl -w use CGI; my $cgi = new CGI; my $nick = $cgi->param('nick'); my $color = $cgi->param('color'); print "Content-type: text/html\n\n"; # HTTP header print "Hello World!
"; # any valid HTML print "$nick likes $color!\n"; # any valid HTML ################################################################################ # do.php Hello World!
################################################################################ # do #!/usr/bin/perl -w use CGI; my $cgi = new CGI; my $nick = $cgi->param('nick'); my $color = $cgi->param('color'); my $name; open FH, 'res/member' or die; # open a file while () { # each line chomp; # truncate the last "\n" character my ( $_name, $_nick ) = split "\t"; # split by tab $_nick eq $nick and $name = $_name and last; # compare } close FH; # close the file $_ = `/bin/cat _hello.html`; # use Linux command s/{name}/$name/g; # replace s/{color}/$color/g; # replace print "Content-type: text/html\n\n$_"; # vi:nowrap:sw=4:ts=4 ################################################################################ # _hello.html

Hello World!

{name} likes {color}!