Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Using XML::Simple with nested arrays

by DamnDirtyApe (Curate)
on Jul 05, 2002 at 00:21 UTC ( #179553=note: print w/replies, xml ) Need Help??

in reply to Using XML::Simple with nested arrays

If you use Data::Dumper along with XML::Simple (the dynamic duo?) you can see that, using forcearray => 1 with XML::Simple, your XML becomes this:

$VAR1 = { 'node' => { 'edge2' => { 'community' => [ 'anotherthing' ], 'loopback' => [ '', '' ] }, 'edge1' => { 'community' => [ 'something' ], 'loopback' => [ '' ] } } };

So, I believe you want something like this:

#! /usr/bin/perl use strict ; use warnings ; use XML::Simple ; #use Data::Dumper ; my $xml = <<'EOD' ; <network> <node name="edge1"> <community>something</community> <loopback></loopback> </node> <node name="edge2"> <community>anotherthing</community> <loopback></loopback> <loopback></loopback> </node> </network> EOD my $data = XMLin( $xml, forcearray => 1 ) ; #print Dumper( $data ) ; foreach my $key ( keys %{$data->{'node'}} ) { foreach my $loopback ( @{$data->{'node'}{$key}{'loopback'}} ) { print "key = $key; loopback = $loopback\n" ; } }


key = edge2; loopback = key = edge2; loopback = key = edge1; loopback =

D a m n D i r t y A p e
Home Node | Email

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://179553]
[BarApp]: I can not use modules. I gain temporary access and still can not use modules.
[Cosmic37]: ta erix - this szabo geezer is pretty cool methinks and he writes about undef but I cannot see instructions for redefining the record separator after having undefined it
[Corion]: $/ = "wahtever";
[Corion]: (it's a magic variable)
[karlgoethebier]: BarApp: whoami
[Cosmic37]: ok fankyou - I was wondering about that but thought there might be a redefine command or something; peachy
[Lotus1]: Cosmic37 if you undef $/ in a local context to a block it won't affect the global version after the block finishes
[Lotus1]: or you can just do local $/ in a block

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2017-06-29 16:48 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (672 votes). Check out past polls.