Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Parse handler for Attributes in XML

by kcott (Archbishop)
on Apr 10, 2012 at 10:09 UTC ( [id://964300]=note: print w/replies, xml ) Need Help??


in reply to Parse handler for Attributes in XML

I'm not particularly familiar with XML::Parser but this line in particular leapt out at me:

if (%attrs eq "command") {

I suspect you want something like:

if (exists $attrs{command}) {

I also noticed your XML has no closing tag (i.e. </DCA>) - possibly a cut-n-paste error.

-- Ken

Replies are listed 'Best First'.
Re^2: Parse handler for Attributes in XML
by balajinagaraju (Sexton) on Apr 10, 2012 at 10:13 UTC
    Thanks Ken, But i want to access specific attributes rather than checking for the presence of the attributes.

      $attrs{command} is a specific attribute. Checking for existence before attempting to access a value (e.g. ... $attrs{command} eq 'some_value' ...) avoids autovivification; depending on what other code you write, this may or may not be important.

      However, the main point I was trying to get across was that %attrs eq "command" was not doing what you wanted/intended/expected. The following short piece of code may help to further explain this:

      $ perl -Mstrict -Mwarnings -E ' > my %x = (a => 1); > say +(%x eq q{a}) ? 1 : 0; > say %x; > say qq{@{[%x]}}; > ' 0 a1 a 1

      -- Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2026-04-23 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.