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