Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Need a better way to count input lines

by japhy (Canon)
on May 07, 2004 at 14:51 UTC ( #351472=note: print w/ replies, xml ) Need Help??


in reply to Need a better way to count input lines

You could do:

# while (not eof FILE) { ... } # or... until (eof FILE) { my (@lines) = map scalar <FILE>, 1 .. 3; # work with $lines[0], $lines[1], $lines[2] }
You need the scalar there, because you only want to get one line at a time.
_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;


Comment on Re: Need a better way to count input lines
Download Code
Re: Re: Need a better way to count input lines
by Theo (Priest) on May 07, 2004 at 20:23 UTC
    I've never used map before. It looks like @lines ends up with three elements because of the "1 .. 3" range. .oO(Verrry useful)
    Would the loop work the same if you used until (eof FILE) instead of the while?

    Update: Thanks for the update!

    -Theo-
    (so many nodes and so little time ... )

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://351472]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-09-21 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (167 votes), past polls