Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: XML::Twig - trying to simplify syntax

by merlyn (Sage)
on Nov 12, 2010 at 01:27 UTC ( #870966=note: print w/ replies, xml ) Need Help??


in reply to XML::Twig - trying to simplify syntax

The problem is that your ... ($my_xpath)[0] ... is being interpreted as  ... ($my_xpath)->[0] ... . As in, the thing on the left is expected to be an arrayref, which it isn't.

You can use a slice to get the proper effect:

my $bar=($twig->get_xpath($my_xpath))[0]->text;
That'll provide list context to the inner expression, and then extract just the 0'th element from that.

-- Randal L. Schwartz, Perl hacker

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.


Comment on Re: XML::Twig - trying to simplify syntax
Select or Download Code
Re^2: XML::Twig - trying to simplify syntax
by smiffy (Pilgrim) on Nov 12, 2010 at 02:01 UTC

    Excellent, works beautifully. Many thanks for that!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2014-08-01 00:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls