Code lifted from the POD in
File::Find::Rule and
HTML::TokeParser::Simple and adapted. Not tested, so proceed with necessary caution, though I don't see any mistakes.
#!/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;
}
Update: fixed some small left-overs from the POD version of the tokeparser code.
Makeshifts last the longest.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.