February 2006
Intermediate to advanced
304 pages
6h 16m
English
The first thing you learn in public speaking is to start off with a joke. So let's start off with a short program that throws up a random joke every time it's run.
1 #!/usr/bin/perl -T
2 # Random joke generator
3 use strict;
4 use warnings;
5
6 use CGI;
7 use CGI::Carp qw(fatalsToBrowser);
8 use HTML::Entities;
9
10 # Untaint the environment
11 $ENV{PATH} = "/bin:/usr/bin";
12 delete ($ENV{qw(IFS CDPATH BASH_ENV ENV)});
13
14 print <<EOF ;
15 Content-type: text/html
16
17 <HTML>
18 <HEAD>
19 <TITLE>Random Joke</title>
20 </HEAD>
21 <BODY BGCOLOR="#FFFFFF">
22 <P>
23 EOF
24
25 my @joke = `/usr/games/fortune`;
26 foreach (@joke) {
27 print HTML::Entities::encode($_), "<BR>\n";
28 }
Read now
Unlock full access