in reply to Re: XML parsing
in thread XML parsing

Sorry, it was mistyped in this form (i should've copy and pasted...). The name attribute is quoted in my xml file. So, the data in the dumped file is not that simple for me to read. How do I make sense of the following: $VAR1 = {
'host' => {
'jimmy.foo.com' => {
'hardware' => 'eht0', 'eht1' ,
'duty' => 'web'
},
The list goes on, but this is detailed info from one host. How do I make this useful. Thanks for being patient with me.

Replies are listed 'Best First'.
Re^3: XML parsing
by jhourcle (Prior) on May 09, 2005 at 22:56 UTC

    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 ); }