Rewriting an Entire Site

Now let’s take a look at Example 14-1, which presents an early version of make_cf.plx. I wrote this script to descend recursively through the CyberFair site, reading in HTML pages and, for those that had the required <META NAME="type" CONTENT="cf"> header, rewriting them from the latest version of the site’s template.

This is a pretty big script to be throwing at you all at once, but most of it consists of components we’ve seen already, either earlier in this chapter or in previous chapters. The new parts will be discussed in detail shortly. As with all the examples in this book, you can download it from the book’s web site, at http://www.elanus.net/book/.

Example 14-1. Early version of make_cf.plx

#!/usr/bin/perl -w # make_cf.plx # rewrite all the pages on the CyberFair site that have 'type' # META headers of 'cf', using the current template. use strict; use File::Find; find(\&process, '/w1/s/socalsail/cyberfair'); sub process { # this is invoked by File::Find's find function for each # file it recursively finds. return unless /\.html$/; my $filename = $File::Find::name; my %page_hash = &read_page($filename); return unless defined $page_hash{type} and $page_hash{type} eq 'cf'; &write_page($filename, &build_page(%page_hash)) or die "couldn't write_page for file '$filename'\n"; } sub read_page { # invoked with a full pathname as argument, # returns a hash suitable for # feeding to &build_page my $pathname = shift; my %return_hash; open IN, "$pathname" or ...

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.