Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: Is it possible to use key/values of a Hash/Hash ref while it's being initialized?

by merlyn (Sage)
on Sep 14, 2005 at 21:54 UTC ( [id://492045]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Is it possible to use key/values of a Hash/Hash ref while it's being initialized?
in thread Is it possible to use key/values of a Hash/Hash ref while it's being initialized?

the current hash being initialized
That hash is necessarily empty until the entire value on the right (the map) is completely computed. You can't start shoving values into there because you can't alter the existing data, or else things like this woudn't work:
@a = map { $a[$_] > 1 ? $a[$_] * 2 : () } 0..$#a;
In this case, you can't start altering @a during the map, because @a might be getting shorter, and then you wouldn't have the right values on the right.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

  • Comment on Re^3: Is it possible to use key/values of a Hash/Hash ref while it's being initialized?
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-23 18:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found