Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Using 'each' to get random (key, value) pair from hash returns "uninitialized value"

by puterboy (Scribe)
on Jan 28, 2011 at 21:08 UTC ( #884926=note: print w/ replies, xml ) Need Help??


in reply to Re: Using 'each' to get random (key, value) pair from hash returns "uninitialized value"
in thread Using 'each' to get random (key, value) pair from hash returns "uninitialized value"

Thanks. I had actually read that sentence but had 'misunderstood' it - thinking of it only in the foreach loop context and not realizing the same thing applies in a non-loop. By the way, your analogy was really helpful.

If I am now understanding the sentence correctly, I can do something like the following:

 ($key, $value) = each %hashCache || each %hashCache;

Presumably this would 'eat' the 'undef' token and make the lazy-a** conductor go back to the front of the bus and start collecting tickets again :)


Comment on Re^2: Using 'each' to get random (key, value) pair from hash returns "uninitialized value"
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (19)
As of 2015-07-30 20:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls