Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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?

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2018-06-24 13:26 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.