Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: If exists (hash)

by packetstormer (Monk)
on Oct 06, 2011 at 15:09 UTC ( #930000=note: print w/ replies, xml ) Need Help??


in reply to Re^3: If exists (hash)
in thread If exists (hash)

Thanks for replying. I did read those threads (in fact I started one of them) but still being relatively new to perl I am having trouble. I notice the following:

My code will retrieve XML results from a web page. The value below will always have data:

$xml->{result}->{covers}

Mostly it will be just a folder path. However, sometimes it could be more than one path in which case the following is returned:

'result' => { 'covers' => {'1' => {'content' => '/mypath/nevr/9smith/' }, '2' => {'content' => '/mypath/nevr/9-dssmith/' }

So when the XML appears I should look for $result->{covers}->{1}->{content}
but this is where the error appears. I'm gonna read up some more and maybe I'll figure it out.
Thanks for the replies though.


Comment on Re^4: If exists (hash)
Select or Download Code
Re^5: If exists (hash)
by choroba (Canon) on Oct 06, 2011 at 15:12 UTC
    I guess you want to check 'HASH' eq ref $xml->{result}{covers}
      Excellent! Thanks. I didn't know anything about "ref" but that is exactly what I needed. I can now do a check to see if its a value of a hashref and then do as I need from there.
      Thanks very much! Working perfect now!
Re^5: If exists (hash)
by Anonymous Monk on Oct 06, 2011 at 15:30 UTC

    . I'm gonna read up some more and maybe I'll figure it out.

    Or you could simply use Data::Diver and be done with it

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (15)
As of 2015-07-01 17:54 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 (15 votes), past polls