Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

XML::LibXML::NodeList get_node

by Anonymous Monk
on Apr 09, 2014 at 10:36 UTC ( #1081631=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have been making good use of XML::LibXML and often have to make use of the get_node function of XML::LibXML::NodeList

I understand that because of xpath it uses a 1 based array rather than a 0 based array. But if I do make the mistake of deriving the 0th value (I am only human :)), then rather than getting an undef or similar I seem to get the -1th value

I can find no mention of this in cpan. Any ideas why this is?

Comment on XML::LibXML::NodeList get_node
Replies are listed 'Best First'.
Re: XML::LibXML::NodeList get_node
by tobyink (Abbot) on Apr 09, 2014 at 11:21 UTC

    get_node is implemented much like this:

    sub get_node { my ($self, $pos) = @_; $self->[$pos - 1]; }

    So $nodelist->get_node(0) is the same as $arrayref->[-1].

    I wouldn't rely on it if I were you though. It's undocumented behaviour that is merely an accident of the internal implementation of XML::LibXML::NodeList, and could theoretically change in the future.

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1081631]
Front-paged by Arunbear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2015-11-28 04:19 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (737 votes), past polls