http://www.perlmonks.org?node_id=1040533


in reply to Nested XML Question

With XML::Simple you have to traverse the structure yourself. Recursion is what you need then.

use strict; use warnings; use XML::Simple; sub findranges { my $text = shift; my $href = shift; print "$text\n"; $text .= ".".$$href{name} if exists $$href{name}; if( exists $$href{"host-group"} ) { for my $name (keys %{ $$href{"host-group"} } ) { findranges( "$text.$name", $$href{"host-group" +}{$name} ); } } if( exists $$href{"ip-address-ranges"} ) { if( ref( $$href{"ip-address-ranges"} ) ) { print "$text\t$_\n" for @{ $$href{"ip-address- +ranges"} }; } else { print "$text\t".$$href{"ip-address-ranges"}."\ +n"; } } } my $xml = XMLin( 'hosts.xml' ); findranges( "", $$xml{'host-group'} );