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
In reply to Re: regex question: store multiple lines as a string
by johngg
in thread regex question: store multiple lines as a string
by nurulnad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |