jh has asked for the wisdom of the Perl Monks concerning the following question:
and I want to populate an array with all the keys in either. It works great if I do it as two steps:%A = (a => 1, b => 2, c => 3); %Z = (z => 9, y => 8, x => 7);
No problem. But I want to do it in one step:%combined = (%A, %Z); @all_keys = keys %combined;
that works fine but it's a little extra (and I know my code is soon going to inflicted on a junior dev, so...) and anyway it seems like I ought to be able to do something simpler. So where it blows up is when I try to do:@all_keys = keys %{{ %A, %Z }};
I get@all_keys = keys(%A, %Z);
...not that the last one is "cleaner" that the version above that works All generate the same error as above, and in fact none but the first work even if I take out the overlay part:@all_keys = keys((%A, %Z)); @all_keys = keys(%temp::var = (%A, %Z)); @all_keys = keys(my %temp = (%A, %Z)); @all_keys = keys(do { %{{%A, %Z}} });
What is going on?@all_keys = keys(%temp::var = (%A)); @all_keys = keys(my %temp = (%A)); @all_keys = keys(do { %{{%A}} });
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem combining hashes
by Corion (Patriarch) on Mar 14, 2024 at 16:38 UTC | |
by jh (Beadle) on Mar 14, 2024 at 19:59 UTC | |
|
Re: Problem combining hashes
by Fletch (Bishop) on Mar 14, 2024 at 16:40 UTC | |
by jh (Beadle) on Mar 14, 2024 at 20:06 UTC | |
|
Re: Problem combining hashes
by LanX (Saint) on Mar 14, 2024 at 22:26 UTC | |
by choroba (Cardinal) on Mar 14, 2024 at 22:58 UTC | |
by Danny (Chaplain) on Mar 15, 2024 at 17:34 UTC | |
by kcott (Archbishop) on Mar 16, 2024 at 02:48 UTC | |
by Danny (Chaplain) on Mar 16, 2024 at 03:32 UTC | |
by LanX (Saint) on Mar 15, 2024 at 21:06 UTC | |
by LanX (Saint) on Mar 15, 2024 at 14:07 UTC | |
by jh (Beadle) on Mar 15, 2024 at 14:06 UTC |