in reply to Slurp a file
Oops. You've just left $/ set to undef for the rest of the program. This can lead to all sorts of nastiness.
Better to do something like this:
my $file_text; { local $/; $file_text = <FILE>; } print $file_text;
Which returns $/ to its original value once you leave the bare block.
Update: I should point out that my correction was to the original version of this node. It's now been changed to use my suggestion.
--<http://www.dave.org.uk>
"Perl makes the fun jobs fun
and the boring jobs bearable" - me
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Slurp a file
by merlyn (Sage) on Jan 08, 2001 at 21:55 UTC | |
by jeroenes (Priest) on Jan 08, 2001 at 21:59 UTC | |
by tilly (Archbishop) on Jan 08, 2001 at 22:52 UTC | |
by tye (Sage) on Jan 08, 2001 at 22:55 UTC | |
by jeroenes (Priest) on Jan 08, 2001 at 23:04 UTC | |
by merlyn (Sage) on Jan 08, 2001 at 22:03 UTC | |
by davorg (Chancellor) on Jan 08, 2001 at 22:07 UTC | |
by tye (Sage) on Jan 08, 2001 at 22:13 UTC | |
|
In Section
Cool Uses for Perl