#14 Random Joke Generator
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.
The Code
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 }
Running the Script
Get Wicked Cool Perl Scripts now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.