mlodato has asked for the wisdom of the Perl Monks concerning the following question:
Such that then $hash1 becomes {key1 => 'value1'} and $hash2 becomes {key2 => 'value2'}?my $hash = { key1 => 'value1', key2 => 'value2', }; my ($hash1, $hash2) = _insert_perl_magic_;
The closest I've gotten is:
But it doesn't seem to work in one line (probably because of some lazy generation or something (I confess I don't truly understand how map works)my @hashes = map { {$_ => $hash->{$_}} } qw(key1 key2); my ($hash1, $hash2) = @hashes;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dereference hash into hashes by key
by soonix (Chancellor) on May 22, 2018 at 16:28 UTC | |
by mlodato (Acolyte) on May 22, 2018 at 16:44 UTC | |
|
Re: Dereference hash into hashes by key
by LanX (Saint) on May 22, 2018 at 16:08 UTC | |
by mlodato (Acolyte) on May 22, 2018 at 16:44 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |