[Wellington-pm] Hash slices with missing keys

Ewen McNeill ewen at naos.co.nz
Wed Jul 19 19:36:55 PDT 2006


In message <1153362727.23524.17.camel at putnam.wgtn.cat-it.co.nz>, Grant McLean wr
ites:
>On Thu, 2006-07-20 at 14:19 +1200, Ewen McNeill wrote:
>> If I have a hash with some fields in it, and I use slices to pick out
>> and swap over some of the values in the hash, and some of the keys
>> referenced in the slice do not exist, am I guarenteed to get undef for
>> the keys that don't exist? [....]
>> @hash{@KEYS_A, @KEYS_B} = @hash{@KEYS_B, @KEYS_A};    # swap values over
>
>Yes, for every element in the union of @KEYS_A and @KEYS_B, the
>corresponding key in %hash will exist after the assignment, regardless
>of whether it existed before and regardless of whether it ends up with a
>value of undef.

Excellent, that's exactly what I want.  Perl's such a handy language.  

Thanks for the prompt response.

Ewen


More information about the Wellington-pm mailing list