Warning: Cannot modify header information - headers already sent by (output started at /data/web/virtuals/85063/virtual/www/domains/waldauf.org/lib/plugins/color/syntax.php:1) in /data/web/virtuals/85063/virtual/www/domains/waldauf.org/inc/actions.php on line 180
programming:perl:hash - WiKi

Hash

Hash of hashes

Hash of Hashes of Arrays

Creating HoHoA:

%HoH = (
    'keyA' =>  { "keyA-01" => [ '1a', '2b', '3c' ],
                 "keyA-01" => [ 1, 2, 3]},
    'keyB' =>  { "keyB-01" => [ 'a', 'b', 'c', 'd' ]}
);


Print all values of keys:

for $ii (keys %HoH) {
  for $oo (keys %{$HoH{$ii}}) {
    print "$ii -> $oo -> @{$HoH{$ii}{$oo}}\n";
  }
}
 
>>> keyB -> keyB-01 -> a b c d
>>> keyA -> keyA-01 -> 1a 2b 3c
>>> keyA -> keyA-02 -> 1 2 3


Print one element of HoHoA:

print $HoH{'keyA'}{"keyA-01"}->[0]."\n";
print $HoH{"keyA"}{'keyA-01'}->[0]."\n";
print @{$HoH{'keyA'}{"keyA-01"}}[0]."\n";
print $HoH{'keyA'}{"keyA-01"}."\n";
 
>>> 1a
>>> 1a
>>> 1a
>>> ARRAY(0x8145578)


Print all elements of HoHoA:

for $ii (keys %HoH) {
  for $oo (keys %{$HoH{$ii}}) {
    for (0..$#{$HoH{$ii}{$oo}}) {
      print "$ii -> $oo -> @{$HoH{$ii}{$oo}}[$_]\n";
    }
  }
}
 
>>> keyB -> keyB-01 -> a
>>> keyB -> keyB-01 -> b
>>> keyB -> keyB-01 -> c
>>> keyB -> keyB-01 -> d
>>> keyA -> keyA-01 -> 1a
>>> keyA -> keyA-01 -> 2b
>>> keyA -> keyA-01 -> 3c
>>> keyA -> keyA-02 -> 1
>>> keyA -> keyA-02 -> 2
>>> keyA -> keyA-02 -> 3
Navigation
Print/export
Toolbox