Skip to Content
Perl for Web Site Management
book

Perl for Web Site Management

by John Callender
October 2001
Beginner
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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

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