When you're posting code on here, you really should wrap your copy/pasted items with <code> ... </code>. I'm guessing you probably saw:
$VAR1 = {
'host' => {
'jimmy.foo.com' => {
'hardware' => ['eht0', 'eht1'],
'duty' => 'web'
},
},
};
So basically, you have a hash of hashes of hashes of something that might be an array. What you'll want to do is force them all to be an array (pass in ForceArray => [ qw(duty) ] to XMLin, or when you create a new XML::Simple object), or you'll have to check for each one:
my $hosts = $data->{'host'};
foreach my $host ( keys %$hosts ) {
my $duties = $hosts->{$host}->{'duty'};
print "$host : $_\n"
foreach ( UNIVERSAL::isa( $duties, 'ARRAY' )
? @$duties
: $duties );
}
|