Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2015-07-02 10:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (33 votes), past polls