in reply to inverting keys in a 2-D Hash
Hello melmoth, and welcome to the Monastery!
I don’t know about the “cleanest” way, but delete works nicely:
#! perl use strict; use warnings; use Data::Dump; my %HASH; $HASH{keyA}{keyB} = [1 .. 4]; dd \%HASH; my $array_ref = $HASH{keyA}{keyB}; delete $HASH{keyB}; delete $HASH{keyA}; $HASH{keyB}{keyA} = $array_ref; dd \%HASH;
Output:
23:53 >perl 1360_SoPW.pl { keyA => { keyB => [1 .. 4] } } { keyB => { keyA => [1 .. 4] } } 23:53 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: inverting keys in a 2-D Hash
by LanX (Saint) on Aug 30, 2015 at 14:21 UTC | |
|
Re^2: inverting keys in a 2-D Hash
by Laurent_R (Canon) on Aug 30, 2015 at 15:16 UTC | |
|
Re^2: inverting keys in a 2-D Hash
by locked_user sundialsvc4 (Abbot) on Aug 31, 2015 at 03:16 UTC |