in reply to Massive File Editing
Update: fixed some small left-overs from the POD version of the tokeparser code.#!/usr/bin/perl -w use strict; use File::Find::Rule; use HTML::TokeParser::Simple; print "Processing:\n"; for my $file (File::Find::Rule->file->name('*.shtml')->in(@ARGV)) { print "\t$file,\n"; rename $file, "$file.old" or die "Cannot rename $file to $file.old +: $!"; open my $fh, ">", $file or die "Cannot open $file for writing: $!" +; my $p = HTML::TokeParser::Simple->new("$file.old"); while (my $token = $p->get_token) { print $fh +( $token->is_start_tag('a') ? new_a_tag($token->return_attr, $token->return_attrseq) : $token->as_is ); } close $fh; } print "done.\n"; sub new_a_tag { my ($attr, $attrseq) = @_; $attr->{href} =~ s</main\.php\?page=!></?id=!> if exists $attr->{h +ref}; map "<a $_>", join ' ', map qq<$_="$attr->{ $_ }">, @$attrseq; }
Makeshifts last the longest.
|
|---|