Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Nested XML Question

by hdb (Monsignor)
on Jun 25, 2013 at 06:04 UTC ( #1040533=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1040533]
[ambrus]: Corion: pre-fork before creating any threads
[ambrus]: it's good practice anyway, even if Linux tolerates forking after creating threads (tolerates, as in, the fork works, but other threads are dead which can lead to interesting deadlocks)
[marto]: could be worse, could be dust
[ambrus]: Corion: if you're forking from perl, then schmorp has a module that helps this prefork magic

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (14)
As of 2017-10-19 14:48 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (253 votes). Check out past polls.