Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: XML::Twig - how can I test for an attribute when the attribute value is 0?

by philiprbrenan (Monk)
on Aug 29, 2012 at 14:14 UTC ( #990478=note: print w/ replies, xml ) Need Help??


in reply to XML::Twig - how can I test for an attribute when the attribute value is 0?

Please assign:

my $f = $label ->att('fq');

and then test whether $f is defined before attempting to decode its actual value.


Comment on Re: XML::Twig - how can I test for an attribute when the attribute value is 0?
Download Code
Re^2: XML::Twig - how can I test for an attribute when the attribute value is 0?
by mertserger (Curate) on Aug 30, 2012 at 08:07 UTC

    I've actually been able to test if it is defined in one step which enabled me to keep the original code structure:if (defined $elt->att('fq') && $la->att('fq') eq '0') does what I need.

    just to show that there is indeed "more than one way to do it" in Perl, I have spotted in another piece of code written usingXML::Twig one of my colleagues used the start tag function and looked for the string "fq=" which would also work but is not as elegant as using defined in my opinion.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2015-07-03 22:40 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 (57 votes), past polls