Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Assigning variables and persistence using Lib::LibXML::Readerby AppleFritter (Vicar) |
on Apr 02, 2017 at 21:38 UTC ( [id://1186753]=note: print w/replies, xml ) | Need Help?? |
EDIT: OK, scratch that, I misunderstood your question. (It's a Sunday night, that's my excuse and I'm sticking to it.) Looking at your sample XML snippet (not well-formed, BTW), it seems that $reader->localName equals "price" twice, when the price tag gets opened and when it gets closed. So $price gets set correctly, but then overwritten again. The easiest (quickest, dirtiest) way to deal with that is to use ||= or //=:
This will only assign to $price if $price is false (||=) or undefined (//=), and leave it be otherwise.
In Section
Seekers of Perl Wisdom
|
|