in reply to Re^2: getfile( $filename )
in thread getfile( $filename )

I wish there was a way to chomp <$FH>.
How about:
my @result = map /(.*)/, <$FH>;
A teeny bit inefficient, but probably insignificant for anything but hammered code.

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

Replies are listed 'Best First'.
Re^4: getfile( $filename )
by japhy (Canon) on Jul 29, 2005 at 12:31 UTC
    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
      First, I wouldn't have expected scalar to take two arguments. True, modern perlfunc pages document this, but it's certainly unexpected to me.

      Second, I dislike modifying $_ in a map, because I believe a map to be applicative, not side-effect-ish.

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

      I'm not sure how that works, but it seems like the map /(.*)/, <> is more perlish. Also, it's shorter.
      Harley J Pig

      Why not my @result = map scalar(chomp, $_), <$FH>?

      That use of scalar gives me the creeps! Isn't this equivalent and less obfuscated?

      my @result = map {chomp; $_} <$FH>;

      Update: or for that matter whats wrong with chomp(my @result = <$FH>);

      --
      Murray Barton
      Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho

Re^4: getfile( $filename )
by harleypig (Monk) on Jul 29, 2005 at 07:55 UTC
    Thanks! Updated.
    Harley J Pig