Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Accessing and array of hashes

by choroba (Archbishop)
on Nov 26, 2014 at 14:42 UTC ( #1108458=note: print w/replies, xml ) Need Help??

in reply to Accessing and array of hashes

$test_data in info::test is an array reference, not a hash reference. You can't dereference it as a hash. What do you want to extract? The name of the first element?
print $test_data->[0]{name};

Or, the names of all the elements?

print join ', ', map $_->{name}, @$test_data;
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Accessing and array of hashes
by Anonymous Monk on Nov 26, 2014 at 15:15 UTC
    I need to access all of them, and it might be more them one block of the same key, so if I print:
    print $print_data->[0]{name}
    it prints 45 occurrences but with the same value.
      Need to use a loop:
      foreach my $detail (@{$test_data}){ my $name = $detail->{name}; print "$name\n"; }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2021-04-13 22:38 GMT
Find Nodes?
    Voting Booth?

    No recent polls found