http://qs321.pair.com?node_id=50529


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
      Tilly pointed me to the use of join in this case. Methinks it's pretty easy:
      $content = join '', <SOMEHANDLE>;
      Chipmunk, just 4u: One might see the actual response of tilly in this node <grin>.

      Jeroen
      I was dreaming of guitarnotes that would irritate an executive kind of guy (FZ)

        That will be slower though.

        The reason I suggested it is in case someone wanted to use your SuperSplit with tied filehandles. I would not depend on a tied filehandle correctly paying attention to $/, so the join makes sense.

        But if you care about performance or have good reason to believe that people won't use tied filehandles, then avoid join.