in reply to $/ is playing havoc with my script.
Setting $/ to something and then setting it back to its previous value, without doing any file input between those two settings, has no effect on anything -- so those two lines assigning to $/ within your while loop are pointless.
In scripts that use modules or that manage more than one input file, it is best to localize changes to $/ within the smallest essential code block, like this:
There are other idioms involving "do { ... }", which would be easy to find here with SuperSearch.my $filecontents; if ( open( FILE, "whatever" )) { local $/; # this sets $/ locally to undef within this block $filecontents = <FILE>; close FILE; } else { die "whatever: $!"; } # all data from "whatever" is now contained in $filecontents # and $/ is now back to its previous value
(updated code snippet to fix missing paren)
|
|---|