rduke15 has asked for the wisdom of the Perl Monks concerning the following question:
The following works, of course:use Data::Dumper; @keys = qw(A B C); @values = qw(1 2 3);
but I would like the results of this clumsy code:@hash{@keys} = @values; print Dumper(\%hash);
... in a shorter and nicer syntax like the 1st example. Unfortunately, whatever I tried, it doesn't "do what I mean":%hash=(); $hash{x}{A} = 1; $hash{x}{B} = 2; $hash{x}{C} = 3; print Dumper(\%hash);
gives me $hash{x}{3} == 3. Writing @hash{x}{@keys} = @values; or @{$hash{x}{@keys}} = @values; doesn't help. Thanks in advance for sharing your wisdom...%hash=(); $hash{x}{@keys} = @values; print Dumper(\%hash);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to $hash{key}{@keys} = @values
by dave_the_m (Monsignor) on Apr 10, 2005 at 16:11 UTC | |
by rduke15 (Beadle) on Apr 10, 2005 at 16:20 UTC | |
by ysth (Canon) on Apr 10, 2005 at 22:52 UTC |