#!/usr/bin/perl
use warnings;
use HTML::Parser;
print("Enter an html file (with either a .html or .htm extension): ");
$file=;
my $file = $ARGV[0];
unless ($file) {
print ("No filename given\n");
exit;
}
my $new;
my $p = HTML::Parser->new(
start_h => [ \&start_h, 'tagname, text' ],
end_h => [\&end_h, 'tagname, text' ],
default_h => [sub { $new .= shift }, 'text'],
);
$p->parse_file($file);
# Rename the old file
my $newfile = $file.'.old';
rename($file, $newfile) or die "Can't rename $file: $!";
# Write the new text to the old filename
open my $fh, ">", $file or die "Can't create new file: $!";
print $fh $new;
close $fh;
sub start_h {
my($tag, $text) = @_;
my $uc = uc $tag;
$text =~ s/$tag/$uc/;
$new .= $text;
}
sub end_h {
my($tag, $text) = @_;
my $uc = uc $tag;
$text =~ s/$tag/$uc/;
$new .= $text;
}