Open Source Development Tutorials | Newsletter Signup | About Us
Search  

Go Back   Open Source Tutorials Forum > Programming Languages > Perl Programming
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-07-2005, 12:16 PM
vsathya79 vsathya79 is offline
Junior Member
 
Join Date: Dec 2005
Posts: 2 vsathya79 is on a distinguished road
Default Perl script to modify HTML

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.
Reply With Quote
  #2  
Old 12-09-2005, 08:17 AM
md_doc md_doc is offline
ubergeek
 
Join Date: Oct 2003
Posts: 204 md_doc has disabled reputation
Post

you would want to do something like this
Code:

$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.
__________________
md
Reply With Quote
  #3  
Old 12-12-2005, 03:07 AM
vsathya79 vsathya79 is offline
Junior Member
 
Join Date: Dec 2005
Posts: 2 vsathya79 is on a distinguished road
Default

It works GREAT. Thank you very much
Reply With Quote
  #4  
Old 12-12-2005, 07:36 AM
md_doc md_doc is offline
ubergeek
 
Join Date: Oct 2003
Posts: 204 md_doc has disabled reputation
Default

You are very welcome!

You might be interested in reading Useful Perl Scripts With Regular Expressions as it covers a lot of common tasks you would do with perl and regular expressions.
__________________
md
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



All times are GMT -5. The time now is 11:17 PM.


Powered by: vBulletin Version 3.0.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright 2004 - 2006 GrindingGears.com. All Rights Reserved.