O'Reilly logo

Perl for Web Site Management by John Callender

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required