Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Struggling with XML

by runrig (Abbot)
on Oct 05, 2012 at 16:03 UTC ( #997506=note: print w/replies, xml ) Need Help??

in reply to Struggling with XML

Another way, w/XML::Rules:
use XML::Rules; my @rules = ( list => sub { my $dict = $_[1]{dict}; for my $d (@$dict) { print "$d->{key}: $d->{value}\n"; } return; }, dict => [ '/root' => sub { my $d = $_[1]; print "$d->{key}: $d->{value}\n" if $d->{key} eq 'status'; return; }, 'no content array', ], value => 'content', ); my $xr = XML::Rules->new( rules => \@rules ); $xr->parse($xml);
Updated to also print status. A possibly simpler way(?):
my @rules = ( "^dict" => sub { return $_[1]{key} =~ /^(?:status|subnet|gateway|netmask|data)$/; }, dict => sub { my $d = $_[1]; return if $d->{key} eq 'data'; print "$d->{key}: $d->{value}\n"; }, value => 'content', );

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997506]
[chacham]: i sent him a private message expressing my displeasure.
[1nickt]: chacham It was worse than 2-1 ! almost 4-1 !
[jdporter]: Dang. No good example of how to use IPC::Run's run() in its simplest mode?
[LanX]: him or her! ;)
[1nickt]: jdporter Maybe try IPC::Run3

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (15)
As of 2017-05-24 20:54 GMT
Find Nodes?
    Voting Booth?