Searching for a pearl of Perl wisdom
October 6, 2005 8:45 AM
Subscribe
Can someone help me figure out how to search and replace case-sensitive filenames in HTML using Perl?
I have a large number of HTML files that include both links and JavaScript tags. I am porting these files over to Linux, where case-sensitivity becomes an issue. Using Perl, I'd like to search through the files, find all instances of src tags or onClick events, and replace the referenced filenames with all lower-case equivalents. The script needs to be aware of the possibility of escape sequences. Additionally, the filename could be surrounded by either single or double-quotes.
I'm a newbie to Perl, but I have searched both CPAN and Google for examples. I am aware of the numerous HTML:: modules in Perl, but am not entirely sure how to implement them for this case. My regular expression skills are still rough around the edges. Any pointers to useful code/examples or discussion of an approach will be greatly appreciated.
posted by nightengine to computers & internet (10 comments total)
s/src=(["'][^"']+)/src=\L$1/g
but I don't know how you'd find filenames in the onClick events where they could be embedded in arbitrary Javascript code.
posted by nicwolff at 9:10 AM on October 6, 2005