in reply to Re: Need help with Piping
in thread Need help with Piping

If I just want the STDIN (or any file content) in a variable, and don't like to loop, I usually use this idiom:

my $var; SLURP: { local $/; $var= <>; }

local-izing $/ in a block undefines it and so no $var gets the whole filecontent sithout looping and reassembling it line by line.


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^3: Need help with Piping
by mscharrer (Hermit) on Aug 13, 2008 at 09:17 UTC
    I like Skeeve's solution. It is the best and clearest way to do this in Perl 5.

    For the sake of completeness: In Perl 6 the built-in way for this is simply:

    $var = slurp \*STDIN;

    This can also be done in Perl 5 by using the Perl6::Slurp module.

Re^3: Need help with Piping
by jasonk (Parson) on Aug 14, 2008 at 01:07 UTC

    You can do all of that in one line...

    my $var = do { local $/ ; <> };

    www.jasonkohles.com
    We're not surrounded, we're in a target-rich environment!