[wplug] Slightly OT- Perl issue

Eric Cooper ecc at cmu.edu
Thu Mar 10 11:04:00 EST 2005


On Thu, Mar 10, 2005 at 10:26:25AM -0500, beer wrote:
> So I am trying to read a file into a scalar.  The typical newbie approach works fine:
> 
> open FILE "<filename";
> while( <FILE> ) {
>  $scalar .= $_;
> }
> close FILE;
> 
> But if I try to slurp the file in:
> 
> open FILE "<filename";
> $scalar = <filename>;
> 
> I end up not getting all of the data.

Tell Perl to ignore line separators:

    undef $/;
    $scalar = <FILE>;

-- 
Eric Cooper             e c c @ c m u . e d u


More information about the wplug mailing list