CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Need help creating a script that reads in multiple files for regex search..replace

 



poly4life
Novice

Mar 24, 2011, 9:39 AM

Post #1 of 2 (1813 views)
Need help creating a script that reads in multiple files for regex search..replace Can't Post

Hello,

I need some help writing a perl script which reads in a series of .htm files, all in the same directory, and executes a regex search..replace on each file. For the replacement, I want the text to be from another file. I am using Windows XP and Strawberry Perl, FYI.

The text for the replace will come from this file:

Code
File_For_Replace.txt 
Way too much text to print in this post, but it is html and will be cut and pasted from another file that I presumably must read in


And the regex will be something like:


Code
#pseudo-code 

s~<html><head></head><body>~Way too much text to print in this post, but it is html and will be cut and pasted from another file that I presumably must read in~ test.htm
# loop through each htm file in a directory


I would sincerely appreciate some help with this. Thank you.


BillKSmith
Veteran

Mar 24, 2011, 10:30 AM

Post #2 of 2 (1799 views)
Re: [poly4life] Need help creating a script that reads in multiple files for regex search..replace [In reply to] Can't Post

It is seldom a good idea to process HTML with regular expressions. There are almost always special cases that you do not think of. Check out several modules on CPAN. Even if you end up doing it yourself, you will probably have learned some of the pitfalls.



I think that you want to replace the body of one valid html document with the body of another. If this is true, even your pseudo-code is not quite right.
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives