Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^5: Counting keys in a hash

by Athanasius (Chancellor)
on Nov 20, 2012 at 14:50 UTC ( #1004729=note: print w/replies, xml ) Need Help??


in reply to Re^4: Counting keys in a hash
in thread Counting keys in a hash

The loop will still work if the data is in an array, won't it?

No, the diamond operator <> is special. In the original loop:

while (<DATA>) {

one line is read on each iteration, and the loop continues until <DATA> returns undef to signal that the data accessed via the filehandle (DATA in this case) has all been read in.

But if you have your data in an array (presumably one line per element), you need a for loop (also spelled foreach — they’re the same):

for (@log) { <code here> }

which iterates over the array until each element has been processed.

(Note that in both loops, the line/element read in on a single iteration is stored in the special variable $_.)

Hope that helps,

Athanasius <°(((><contra mundum

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004729]
help
Chatterbox?
marioroy just logged in to say that MCE::Hobo has passed testing and therefore will continue to run like threads but have managed capabilities similar to Parallel:: ForkManager. It allows multiple managed instances to run simultaneously. Zero limitations.
marioroy it's taken a long time to make this possible.
marioroy will post demonstrations after release

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-07-28 19:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (433 votes). Check out past polls.