cliftonsnyder.net - code

sub-nav.pl [download]

the script I use to ensure that all of the nav links in this site stay up-to-date

source

#!/usr/bin/perl
#
# sub-nav.pl - replace nav links
#
my $usage = "usage: sub-nav.pl navfile htmlfile";
my $nav = shift;
my $htm = shift;

open NAV, "<$nav" or die "$!\n$usage\n";
open HTM, "<$htm" or die "$!\n$usage\n";

my $p = "zoinks";
while(<HTM>){
    if(m/<!-- begin nav -->/){
	print "<!-- begin nav -->\n";
        $p=""; # stop printing shit
	while(<NAV>){
	    print $_;
	}
    }elsif(m/<!-- end nav -->/){
	$p = "scoob"; # start printing again
    }
    print $_ if $p;
}

close NAV;
close HTM;

Note: syntax-highlighted HTML code generated using code2html