Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: perl & XML: getting last child?

by Your Mother (Chancellor)
on Apr 17, 2013 at 20:25 UTC ( #1029218=note: print w/ replies, xml ) Need Help??


in reply to perl & XML: getting last child?

*A* way.

use strictures; use XML::LibXML; my $dom = XML::LibXML ->load_xml({ IO => \*DATA }); my $last = [ $dom->findnodes("/library/book[last()]") ]->[0]; print $last->findvalue("title"), $/; __DATA__ <library> <book> <title>Perl Best Practices</title> <src>Use python. But I keed!</src> </book> <book> <title>Perl Cookbook, Second Edition</title> <src>You would make more cooking meth. But I keed!</src> </book> <book> <title>Guitar for Dummies</title> <src>Stratocaster. Oh, I'm sorry, did I stutter?</src> </book> </library>


Comment on Re: perl & XML: getting last child?
Download Code
Replies are listed 'Best First'.
Re^2: perl & XML: getting last child?
by Lotus1 (Chaplain) on Apr 17, 2013 at 21:09 UTC

    Another way is:

    my ($last) = $dom->findnodes("/library/book[last()]");

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1029218]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2015-07-31 06:26 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 (274 votes), past polls