in reply to pulling data from a complex structure
Using each for navigating hashes can clean things up a little:
use strict; use warnings; my %netMap = ( 'LSS1' => { 'LUN1' => [qw(HOST1 HOST2 HOST3)], 'LUN2' => [qw(HOST1 HOST2)], }, 'LSS2' => { 'LUN3' => [qw(HOST5 HOST6)], 'LUN4' => [qw(HOST1)], }, ); while (my @entry = each %netMap) { print $entry[0] . "\n"; while (my @lun = each %{$entry[1]}) { print " $lun[0]\n"; print " $_\n" for @{$lun[1]}; } }
Prints:
LSS2 LUN4 HOST1 LUN3 HOST5 HOST6 LSS1 LUN2 HOST1 HOST2 LUN1 HOST1 HOST2 HOST3
The down side is that you can't control the output order, it is dictated by the enumeration order returned by each.
|
|---|