I'm required to write a script that will take an HTML document and alter the tags to all be upper case.
for example
would output
I can open files and use the tr/// function easily enough, its just getting it to ignore anything outwith<> and within "".
Current code:
for example
Code:
<html> <head> <title>Please help I'm going mad</title> </head> <body> <img src="pic.gif></img> </body> </html>
Code:
<HTML> <HEAD> <TITLE>Please help I'm going mad</TITLE> </HEAD> <BODY> <IMG SRC="pic.gif></IMG> </BODY> </HTML>
Current code:
Code:
#!/usr/local/bin/perl
print "Enter name of file you wish to edit.\n";
chomp ($filename = <STDIN>);
validateExtension();
readTags();
sub validateExtension
{
if ($filename =~ m/\w{1,}[.]{1}[htmlHTML]{3,4}$/)
{
print "pass\n";
}
else
{
print "fail\n";
}
}
sub readTags
{
open(READFILE, "$filename") || die "Couldn't open the file: $!";
while(<READFILE>)
{
$_ =~ tr/[a-z]/[A-Z]$/;
}
close(READFILE);
}
Comment