Perl script to modify HTML
Read With Formatting | Free Open Source Tutorials Account
Perl Programming
Thread: Perl script to modify HTML
vsathya79
I need a perl script to insert some text just after <body XXXX> open tag.
For Ex:
<html><body bgcolor='#FFFFFF'></body></html>
should result in
<html><body bgcolor='#FFFFFF'>This is my text</body></html>
Please note that the body open tag may differ at times.
Please help me.
md_doc
you would want to do something like this
$string ~= s/<body(.*?)>/<body$1>new stuff/;
You might need to do something like /i; if body might be capitalized.
You might need to do /s; if the body tag might not be on the same line.
I would not suggest doing /g; because that is for replace every occurance in the string and body should only be found once.
vsathya79
It works GREAT. Thank you very much
md_doc
You are very welcome!
You might be interested in reading Useful Perl Scripts With Regular Expressions (http://www.opensourcetutorials.com/tutorials/Server-Side-Coding/Perl/perl-scripts-regex/page1.html) as it covers a lot of common tasks you would do with perl and regular expressions.