#!/usr/bin/perl -w # fix_links.plx # this script processes all the *.html files whose names are supplied # to it on the command line, replacing all HREF attributes # that point to local resources in the current directory # with rewritten versions that have: # # 1) '.htm' extensions changed to '.html', and # 2) VaRiEnT captialization uniformly downcased. foreach $file (@ARGV) { unless (-f $file) { warn "$file is not a plain file. Skipping...\n"; next; } unless ($file =~ /\.html$/) { warn "$file doesn't end in .html. Skipping...\n"; next; } if ($file =~ m{/}) { warn "$file contains a slash. Skipping...\n"; next; } $content = ''; open IN, $file or die "can't open $file for reading: $!"; while ($line = ) { # for HREF attributes pointing to the current directory, # downcase attribute, and rename '.htm' to '.html' $line =~ s/HREF="([^"\/]+\.htm)"/HREF="\L$1\El"/gi; $content .= $line; } close IN; # print $content, to check the changes # print "File $file, after changes:\n\n$content\n"; open OUT, "> $file" or die "can't open $file for writing: $!"; print OUT $content; close OUT or die "can't close $file after writing: $!"; }