Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How can I assign the elements in an array to only the key values in a hash?

by MeowChow (Vicar)
on Mar 31, 2001 at 06:19 UTC ( [id://68599]=note: print w/replies, xml ) Need Help??


in reply to How can I assign the elements in an array to only the key values in a hash?

I prefer:
undef @hash{@array};
While this does exactly the same thing as the above, the syntax of @hash{@array} = undef is misleading, since only the first hash value is explictly set to undef, while the rest are implicitly undef'd. Novices who see this code might later write the following, expecting it to set all hash values to 1:
@hash{@array} = 1;
Of course, only the first hash value is set to 1 in this case, and the rest become undef.
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

Replies are listed 'Best First'.
(ar0n) Re: Answer: How can I assign the elements in an array to only the key values in a hash?
by ar0n (Priest) on Mar 31, 2001 at 21:09 UTC

Log In?
Username:
Password:

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

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

    No recent polls found