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

Re^4: Bad index while coercing array into hash

by Anonymous Monk
on Aug 25, 2014 at 20:25 UTC ( #1098553=note: print w/replies, xml ) Need Help??

in reply to Re^3: Bad index while coercing array into hash
in thread Bad index while coercing array into hash

Hmm, well, you can't treat a string as a hash or an array as a hash or a hash as an array

You can use eval to trap errors, ref to interrogate values to see what kind of reference they are, or Data::Diver which combines both, Re: Parsing SOAP::Lite results (with Data::Diver)

use strict; use warnings; use JSON qw/ encode_json decode_json /; my $json = <<'__JSON__'; { "fields" : { "customfield_11872" : [ { "name" : "", "self" : " +372", "released" : false, "id" : "35372", "archived" : false, "description" : "Null version. May be deleted after other +conforming versions are created" } ] } } __JSON__ my $decoded_json = decode_json( $json ); print $decoded_json->{'fields'}{'customfield_11872'}[0]{'name'}, "\n"; use Data::Diver qw/ Dive /; if( my $toyArrRef = Dive $decoded_json, qw/ fields customfield_11872 / + ){ for my $toy ( @{ $toyArrRef } ){ if( my $name = Dive $toy, qw/ name / ){ print "Name is $name\n"; } } } __END__ Name is

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2018-10-22 12:59 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (119 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!