#!/usr/local/bin/perl -w #################################### # Author:Shraddha Kulkarni # smart_html.pl # This script takes html filename as the argument. # Re-writes all tags and attributes in lower-case and adds double quotes to attribute values if missing. # Old files are backed up in the same directory by appending .old to the original filename. ##################################### use strict; use File::Copy; if (@ARGV == 0){ print "You need to provide paths of the html files as arguments.\n"; exit; } for (@ARGV){ my $cur_file=$_; my $tmp_file=$cur_file.".tmp"; open HTML,$cur_file; open NEWHTML,">".$tmp_file; while(){ s/\<(\/?)([\w]+)/\<$1\L$2\E/g; ## lowercase the tags while(s/\<([\w]+)(.*?)(\s[\w]*[A-Z]+[\w]*=)(.*?)\>/\<$1$2\L$3\E$4\>/){} # lowercase the attributes while(s/\<([\w]+)(.*?)(\s[\w]+=)([\w]+)(.*?)\>/\<$1$2$3"$4"$5\>/){} # put double quotes to attribute values if missing print NEWHTML $_; } close NEWHTML; close HTML; move($cur_file,$cur_file.".old"); move($tmp_file,$cur_file); print "Old file backed up at $cur_file".".old\n"; }