Just wanted to share this nice little script for safe upcasing of HTML
tag and attribute names.
Don't ask me why anybody would want to do that :-)
Regards,
Gisle
--------------------------------------------------
#!/usr/bin/perl
use strict;
use HTML::Parser ();
sub upcase_tag
{
my($text, $tpos) = @_;
while (@$tpos) {
substr($text, shift @$tpos, shift @$tpos) =~ tr/a-z/A-Z/;
shift @$tpos while @$tpos % 4; # skip attribute value
}
print $text;
}
my $p = HTML::Parser->new(api_version => 3);
$p->handler(default => sub { print @_ }, "text");
for (qw/start end/) {
$p->handler($_ => \&upcase_tag, "text, tokenpos");
}
my $file = shift || usage();
$p->parse_file($file) || die "Can't open file $file: $!\n";
sub usage
{
my $progname = $0;
$progname =~ s,^.*/,,;
die "Usage: $progname <filename>\n";
}