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