XML::Twig question

XML::Twig question

am 23.12.2007 20:25:11 von goldtech

Hi,

Trying this but only "aaa" outputs not "bbb". What's fix? I'm new to
XML and Perl - help appreciated.

xml file:




aaa
bbb




perl file:

#!/usr/bin/perl -w
use strict;
use XML::Twig;

my $twig= XML::Twig->new( twig_roots => {'/config/attrbs' =>
\&do_attrb});
$twig->parsefile( "xmlt1.xml");
$twig->purge();

sub do_attrb {
my($a1) = $_->find_nodes("attrb");
print $a1->text, "\n";
}


output:

aaa

Re: XML::Twig question

am 24.12.2007 12:34:15 von mirod

On Dec 23, 2:25 pm, goldtech wrote:

> my($a1) = $_->find_nodes("attrb");
> print $a1->text, "\n";

find_nodes returns a list of nodes, so the first line here
assigns the first element of that list to $a1.

I think you want
my @attrb= _->find_nodes("attrb");
print map { $_->text } @attrb;

Does that help?

--
mirod

Re: XML::Twig question

am 24.12.2007 22:41:43 von goldtech

....snip...
>
> I think you want
> my @attrb= $_->find_nodes("attrb");
> print map { $_->text } @attrb;
>
> Does that help?
>

Perfect - Thank you.