Skip to Main Content
Perl for Web Site Management
book

Perl for Web Site Management

by John Callender
October 2001
Beginner content levelBeginner
528 pages
15h 20m
English
O'Reilly Media, Inc.
Content preview from Perl for Web Site Management

Inserting the Links

As mentioned earlier, the rest of that long if-elsif section simply repeats, with minor variations, the same process of creating a $link_string suitable for the page currently being processed by the enclosing foreach loop. Down at the bottom of that foreach loop, after the long if-elsif section, comes the following chunk of code:

if ($link_string) {
    $link_string =~ s/<BR>\n$//;
    $link_string = "$link_start$link_string$link_end";
}

$link_string .= "\n$more_string\n";

This does a cleanup on the $link_string variable, removing a trailing <BR>\n it might have in the case of certain types of pages. It also appends another variable to it, called $more_string, that might have received some content in the case of certain kinds of pages. You can examine the if-elsif block to see how those cases work, if you’re curious, but we won’t be discussing them here.

Finally, we use a substitution operation to take the $made_page variable (which you’ll recall contains the newly re-created version of the current page) and insert the cleaned-up $link_string variable into it just below the <!--end content--> comment. Then we use the &write_page routine to replace the actual version of the page on the web site with our new version of it:

$made_page =~ 
    s{(<!--\s*end\s+content\s*-->)}{$1\n\n$link_string}i;

&write_page($path, $made_page) or die "&write_page failed";

And that’s it. By running this script when the site’s collection of student and leader pages has changed, we can update all ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Web Client Programming with Perl

Web Client Programming with Perl

Clinton Wong
Embedding Perl in HTML with Mason

Embedding Perl in HTML with Mason

Ken Williams, Dave Rolsky

Publisher Resources

ISBN: 1565926471Catalog PageErrata