There's more than one way to do things | |
PerlMonks |
Re: HTML document modificationby BrowserUk (Patriarch) |
on May 28, 2004 at 02:04 UTC ( [id://357116]=note: print w/replies, xml ) | Need Help?? |
Maybe if you read the file backwards and only replaced the last (first:) occurance of </body>. If your html is well formed that should be fairly foolproof. Perhaps, rather than reading backwards line by line, you could read the last couple of hundred bytes and then use the regex
By only replacing the /body tag if there is only whitespace and an (optional) /html tag between it and the EOF, you'd be pretty certain of correctness assuming reasonably well-formed html. That wouldn't handle comments, but they are (probably) fairly rare at that point in the html? If you raised an error in the event that the regex didn't match, any oddities could be fixed up manually. Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham"Think for yourself!" - Abigail
In Section
Seekers of Perl Wisdom
|
|