in reply to getfile( $filename )

my $contents = do { local(*ARGV, $/); @ARGV = "filename"; <> };

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: getfile( $filename )
by harleypig (Monk) on Jul 29, 2005 at 03:46 UTC
    Yeah, I've run across that little ditty before, most recently as a yak shaving on my IPC::Open3 journey, but it doesn't handle wantarray. It just occurred to me that it doesn't chomp the lines either ... hmmm ...
    return wantarray ? do { my @lines = <$FH> ; chomp @lines ; @lines } : do { local $/ ; <$FH> };
    I wish there was a way to chomp <$FH>.
    Harley J Pig
        Why not my @result = map scalar(chomp, $_), <$FH>?

        Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
        How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
        Thanks! Updated.
        Harley J Pig