A Script for Creating HTML Documents
Example 17-1 shows the CGI script that we used. It’s a long one, but I’ll be explaining all the interesting Perl features it contains. Like all the examples in this book, you can download it from the book’s web site, at http://www.elanus.net/book/.
Example 17-1. A CGI script to create new pages in the CyberFair docbase
#!/usr/bin/perl -Tw # make_page.cgi # gives a cgi frontend to allow users to # create a new cyberfair student or leader page use strict; use lib '/home/jbc/lib'; use Cyberfair::Page qw(read_page build_page write_page); $ENV{PATH} = ''; use CGI qw(:standard); my $action = param('action'); my $fs_root = '/w1/s/socalsail/cyberfair'; my $escaped_fs_root = quotemeta $fs_root; my $web_root = '/cyberfair'; my ($content, $err_msg); use File::Find; my @student_strings; # elements are strings of the form: # 'teacher_short_name/student_short_name' my %teacher_name; # key: teacher short_name, # value: teacher long_name my %cat_name; # key: cat short_name, value: cat long_name. find(\&load_pages, $fs_root); # loads up the variables listed above @student_strings = sort @student_strings; # each of the subroutines below loads up the $content variable # with the content to be delivered back to the user. unless ($action) { &show_links; } elsif ($action eq 'show_student_form') { &show_student_form; } elsif ($action eq 'show_leader_form') { &show_leader_form; } elsif ($action eq 'Create student page') { &post_student_page; } elsif ($action eq 'Create ...
Get Perl for Web Site Management 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.