Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Weird function calling...

by robin (Chaplain)
on Jan 07, 2002 at 23:25 UTC ( [id://136900]=note: print w/replies, xml ) Need Help??


in reply to Weird function calling...

If you rewrite the loop as:
while (my ($key, $func) = each %Movement) { $foo->$func; }
then you avoid the problem altogether, and you also avoid having to drop the whole key list onto the stack and dereference the hash needlessly.

I think each is underused, and is a better idiom for many loops which use keys.

Replies are listed 'Best First'.
Re: Re: Weird function calling...
by merlyn (Sage) on Jan 07, 2002 at 23:31 UTC
      I must admit I'd assumed that dragonchild was using the key, but had omitted it from the example code for the sake of simplicity. Why use a hash at all, otherwise? But I shouldn't make assumptions without mentioning them.

      Your code is very neat and concise, but if the hash is large, it may be impractical to dump all the values onto the stack. each really has much nicer semantics, even if it's slightly more cluttered syntactically. Of course, when we get lazy lists in Perl 6 we might be able to have both at once :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-03-29 11:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found