Keep It Simple, Stupid | |
PerlMonks |
Re: Regexps to change HTML tags/attributesby Abigail-II (Bishop) |
on Aug 27, 2003 at 16:04 UTC ( [id://287077]=note: print w/replies, xml ) | Need Help?? |
There's much wrong with your program. First, if you are
going to modify the file line-by-line, it's a total waste
to first read in all lines into an array. However, when
dealing with HTML, it's wrong to look at individual lines.
HTML does not have a concept of lines, and tags can have
newlines inside them.
As for the regexes, the first pattern will not do the right thing if there's another tag at the same line. The second pattern will fail to do the right thing if the anchor has another attribute before "HREF", or if it has an attribute value containing a ">". You would be far better off using one of the many HTML parsing modules found on CPAN. Abigail
In Section
Seekers of Perl Wisdom
|
|