in reply to regex question: store multiple lines as a string
However, if I want to read another text file line by line in the same perl script, redefining $/ = "\n" doesn't work.
It will depend on whether you are reading the other file in the same lexical scope. If you are not then you can localise the scope of your redefine of $/; you should be doing this anyway as a habit to avoid the side effects you describe.
{ local $/ = q{}; # paragraph mode in this scope while ( <$file1FH> ) { # do something with the multi-line record # from file1 ... } } ... # $/ now back to normal while ( <$file2FH> ) { # do something with a line from file2 ... }
I hope this is helpful.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex question: store multiple lines as a string
by nurulnad (Acolyte) on Oct 12, 2010 at 11:26 UTC |