http://www.perlmonks.org?node_id=24191


in reply to Load file into a scalar without File::Slurp

I usually use this Perl Golf-ish subroutine that doesn't require a filehandle:
$contents=slurp('foobar'); sub slurp {local$/=<>if local@ARGV=@_}
or use an in-line block:
{local$/;$contents=<>if local@ARGV='foobar'};
or, if you could afford a filehandle and wasted CPU time:
$contents=join'',<_>if open _,'foobar';
Of course, if this is really a Perl Golf contest entry, I'll probably write:
$contents=`cat foobar`
But it's platform dependent and cheating, so don't do that. :-p

/Autrijus/