Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^2: Forcing array context on a file handle

by perl_walker (Novice)
on Oct 31, 2012 at 07:15 UTC ( #1001614=note: print w/replies, xml ) Need Help??

in reply to Re: Forcing array context on a file handle
in thread Forcing array context on a file handle

Hi, ronmrdechai

$lines = grep {$_} <$file>;

Replies are listed 'Best First'.
Re^3: Forcing array context on a file handle
by QM (Parson) on Nov 02, 2012 at 12:31 UTC
    That works for files in the default case, because every line will have a newline or somesuch, and will not be an empty string. For counting, map would be more appropriate than grep. But tobyink showed the idiom above:
    my $lines =()= <$file>;

    Quantum Mechanics: The dreams stuff is made of

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1001614]
[marto]: at times mine surprise me with this behavior :)
[Corion]: I mean, in a way it would be nicer+easier if they always where that obedient, but it's comforting to see that they are when it matters, at least for now ;)

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2016-12-08 09:33 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (138 votes). Check out past polls.