Differences

This shows you the differences between two versions of the page.

Link to this comparison view

programming:perl:hash [2014/04/01 18:02]
waldauf
programming:perl:hash [2015/03/31 22:45] (current)
Line 1: Line 1:
-====== Hash ====== +====== Hash ======  
- +  
- +  
-===== Hash of hashes ===== +===== Hash of hashes =====  
- +  
- +  
-===== Hash of Hashes of Arrays ===== +===== Hash of Hashes of Arrays =====  
- +  
-Creating HoHoA:<code perl> +Creating HoHoA:<code perl>  
-%HoH = ( +%HoH = (  
-    'keyA' =>  { "keyA-01" => [ '1a', '2b', '3c' ], +    'keyA' =>  { "keyA-01" => [ '1a', '2b', '3c' ],  
-                 "keyA-01" => [ 1, 2, 3]}, +                 "keyA-01" => [ 1, 2, 3]},  
-    'keyB' =>  { "keyB-01" => [ 'a', 'b', 'c', 'd' ]} +    'keyB' =>  { "keyB-01" => [ 'a', 'b', 'c', 'd' ]}  
-); +);  
-</code> +</code>  
- +  
-\\ +\\  
-Print all values of keys:<code perl> +Print all values of keys:<code perl>  
-for $ii (keys %HoH) { +for $ii (keys %HoH) {  
-  for $oo (keys %{$HoH{$ii}}) { +  for $oo (keys %{$HoH{$ii}}) {  
-    print "$ii -> $oo -> @{$HoH{$ii}{$oo}}\n"; +    print "$ii -> $oo -> @{$HoH{$ii}{$oo}}\n";  
-  } +  }  
-+}  
- +  
->>> keyB -> keyB-01 -> a b c d +>>> keyB -> keyB-01 -> a b c d  
->>> keyA -> keyA-01 -> 1a 2b 3c +>>> keyA -> keyA-01 -> 1a 2b 3c  
->>> keyA -> keyA-02 -> 1 2 3 +>>> keyA -> keyA-02 -> 1 2 3  
-</code> +</code>  
- +  
-\\ +\\  
-Print one element of HoHoA:<code perl> +Print one element of HoHoA:<code perl>  
-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'}->[0]."\n";  
-print @{$HoH{'keyA'}{"keyA-01"}}[0]."\n"; +print @{$HoH{'keyA'}{"keyA-01"}}[0]."\n";  
-print $HoH{'keyA'}{"keyA-01"}."\n"; +print $HoH{'keyA'}{"keyA-01"}."\n";  
- +  
->>> 1a +>>> 1a  
->>> 1a +>>> 1a  
->>> 1a +>>> 1a  
->>> ARRAY(0x8145578) +>>> ARRAY(0x8145578)  
-</code> +</code>  
- +  
-\\ +\\  
-Print all elements of HoHoA:<code perl> +Print all elements of HoHoA:<code perl>  
-for $ii (keys %HoH) { +for $ii (keys %HoH) {  
-  for $oo (keys %{$HoH{$ii}}) { +  for $oo (keys %{$HoH{$ii}}) {  
-    for (0..$#{$HoH{$ii}{$oo}}) { +    for (0..$#{$HoH{$ii}{$oo}}) {  
-      print "$ii -> $oo -> @{$HoH{$ii}{$oo}}[$_]\n"; +      print "$ii -> $oo -> @{$HoH{$ii}{$oo}}[$_]\n";  
-    } +    }  
-  } +  }  
-+}  
- +  
->>> keyB -> keyB-01 -> a +>>> keyB -> keyB-01 -> a  
->>> keyB -> keyB-01 -> b +>>> keyB -> keyB-01 -> b  
->>> keyB -> keyB-01 -> c +>>> keyB -> keyB-01 -> c  
->>> keyB -> keyB-01 -> d +>>> keyB -> keyB-01 -> d  
->>> keyA -> keyA-01 -> 1a +>>> keyA -> keyA-01 -> 1a  
->>> keyA -> keyA-01 -> 2b +>>> keyA -> keyA-01 -> 2b  
->>> keyA -> keyA-01 -> 3c +>>> keyA -> keyA-01 -> 3c  
->>> keyA -> keyA-02 -> 1 +>>> keyA -> keyA-02 -> 1  
->>> keyA -> keyA-02 -> 2 +>>> keyA -> keyA-02 -> 2  
->>> keyA -> keyA-02 -> 3+>>> keyA -> keyA-02 -> 3
 </code> </code>
Navigation
Print/export
Toolbox