Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Answer: Apply regex to entire file, not just individual lines ?

by dsb (Chaplain)
on Jan 24, 2001 at 02:49 UTC ( #53830=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > Apply regex to entire file, not just individual lines ? - Answer contributed by dsb

The key is two get the whole file into one scalar( the first 'while' loop). Then the 'g' modifier ( the condition in the second 'while' loop ) will keep the place of the last match found and continue from there until there are no matches found.
open( FH, "filename" ) || die "couldn't open\n"; while ( <FH> ) { $data .= $_; } while ( $data =~ m/PATTERN/g ) { # executed code # executed code...etc. }
-kel

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
NodeReaper waits for the new pizza guy, again

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2017-05-26 17:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?