in reply to Re: Array / Hash Confusion!
in thread Array / Hash Confusion!

thanks for your reply. I understand I need to store the result in a scalar and thanks for your suggested code, which I've seen works in my env.

it clearly works for "$data->{title}"; as this is a single result, but when "$data->{genres}"; this returns ARRAY(gobblydegook) as expected.

how do I effectively test if a result is an array or not, and then jump into it? or should I be converting this into a hash and trying to look at key/value combinations?

Replies are listed 'Best First'.
Re^3: Array / Hash Confusion!
by SuicideJunkie (Vicar) on Jan 07, 2014 at 20:03 UTC
    ref is handy:
    foreach my $key (keys %$data) { my $thing = $data->{$key}; if (ref $thing eq 'HASH') { useThingAsHashRef($thing); }elsif (ref $thing eq 'ARRAY') { useThingAsArray($thing); } }
Re^3: Array / Hash Confusion!
by toolic (Bishop) on Jan 07, 2014 at 20:03 UTC
    If you know it is an array:
    print "$_\n" for @{ $data->{genres} };

    See also: