Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Bad index while coercing array into hash

by Anonymous Monk
on Jun 08, 2007 at 20:09 UTC ( #620080=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

My code
print Dumper ($self->result->{Abcd}); print "\n Platform ="; print Dumper ($self->result->{Abcd}->{Platfor +m}); print "\n abcdname ="; print Dumper ($self->result->{Abcd}->{AbcdNam +e});
output with error
$VAR1 = [ { 'Platform' => '12000', 'AbcdName' => 'slhrno1', 'DedicatedOption' => '-1', 'ShortName' => 'BRYN1', 'AFlag' => 'N', 'AbcdId' => '47358', 'Vendor' => 'MICROSOFT', 'Type' => '21', 'AliasName' => 'stlt', 'ExportVersion' => 'US' } ]; Platform =$VAR1 = undef; abcdname =Bad index while coercing array into hash at xxx.pm line 33

I dont see 'AbcdName' as array, also 'Platform' got value of 12000 but output shows undef....

any help?

Code tags added by GrandFather

Comment on Bad index while coercing array into hash
Select or Download Code
Re: Bad index while coercing array into hash
by FunkyMonk (Canon) on Jun 08, 2007 at 20:46 UTC
    my $VAR1 = { 'Platform' => '12000', 'AbcdName' => 'slhrno1', 'Dedicate +dOption' => '-1', 'ShortName' => 'BRYN1', 'AFlag' => 'N', 'AbcdId' => + '47358', 'Vendor' => 'MICROSOFT', 'Type' => '21', 'AliasName' => 'st +lt', 'ExportVersion' => 'US' } ; print "\n Platform ="; print Dumper ($VAR1->{Platform}); print "\n abcdname ="; print Dumper ($VAR1->{AbcdName});

    Produces:

    Platform =$VAR1 = '12000'; abcdname =$VAR1 = 'slhrno1';

    All I can do is guess, because I've only seen a snippet of your code, but I think $self->result is doing something it shouldn't. Don't forget that Carp and similar "lie" about where an error has occurred, reporting an error in a module as if it were an error in the call.

Re: Bad index while coercing array into hash
by kwaping (Priest) on Jun 08, 2007 at 22:58 UTC
    Your $self->result->{Abcd} is actually an array of hashrefs. Try printing $self->result->{Abcd}[0]{Platform} instead.

    ---
    It's all fine and dandy until someone has to look at the code.
      thanks kwaping, its working...
        Can someone please help me on this : The output of the custom field when run via api query: "customfield_11872": [ { "self": "https://localhost.com:8080/rest/api/2/version/35372", "id": "35372", "description": "Null version. May be deleted after other conforming versions are created", "name": "0.0.0.0", "archived": false, "released": false } the command that i used is shown below: my $decoded_json = decode_json($result); $jira_found_in_release = "$decoded_json->{'fields'}{'customfield_11872'}{'name'}; When the customfield name value is null, I do not get any error but when the name field contains value such as 0.0.0.0 , i get bad index while corecing array into hash... Can someone please tell me how to store the value into $jira_found_in_release variable.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (14)
As of 2014-08-27 15:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (242 votes), past polls