Gossamer Forum
Home : General : Perl Programming :

Bad index while coercing array into hash at ...

Quote Reply
Bad index while coercing array into hash at ...
Anyone got any ideas what this error message is all about?

Quote:
[Sat Nov 6 03:48:46 2004] hotelclub_xml.cgi: Bad index while coercing array into hash at xml.cgi line 434.

The surrounding area of code, is;

Code:
# Address...
if (defined $xmld->{Address}) {
$link_details->{PostalCode} = $xmld->{Address}->{PostalCode};
if ($xmld->{Address}->{StateCode}) {
$link_details->{State} = $_states_hash->{$xmld->{Address}->{StateCode}};
}
if (defined $xmld->{Address}->{CountryCode}) {
$link_details->{Country} = $_countries_hash->{$xmld->{Address}->{CountryCode}};
}
$link_details->{City} = $xmld->{Address}->{City};
$link_details->{Line1} = $xmld->{Address}->{Line1};
#print "Directions: " . $xmld->{Directions} . "\n"; next;
if (defined $xmld->{Directions}) {
$link_details->{Directions} = $xmld->{Directions}->{Text};
}
}

The part in red is line 434.

TIA for any ideas/suggestions. I've been struggling with this for over a day now Frown

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Bad index while coercing array into hash at ... In reply to
Use Data::Dumper and dump $xmld and see what $xmld->{Directions} has in it. It looks like it might be an arrayref instead of a hashref. Post the dump here if you can.

~Charlie
Quote Reply
Re: [Chaz] Bad index while coercing array into hash at ... In reply to
Yeah, you're right.

use Data::Dumper;
print Dumper($xmld->{Recreation}[0]);

(example)

However, the problem is... that this script needs to accomidate the [0] and also the non-array.

Its gonna be messy.. but I guess I'll need to accomidate for both (not really the best thing to be trying to figure out with a bump on you're head...LOL).

I've seen stuff like;

Code:
if (array $var) {
.. work with the array
} else {
... work without an array
}

... guess I better start looking into that :(

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Bad index while coercing array into hash at ... In reply to
It shouldn't be hard depending on what you need to with the data:

Code:
if (ref($xmld->{'key'}) eq 'ARRAY') {
...
}

~Charlie
Quote Reply
Re: [Chaz] Bad index while coercing array into hash at ... In reply to
Thats the beauty.... thanks Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!