Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Cannot use foreach on array of hashes

by tobyink (Canon)
on Dec 18, 2019 at 13:03 UTC ( [id://11110334]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Cannot use foreach on array of hashes
in thread Cannot use foreach on array of hashes

Square brackets [...] in a data structure like that is a reference to an array. A list (...) within a data structure like that is pretty meaningless as lists get flattened.

Either of the following two are the correct way of iterating through it:

my $aktData = $aktivitaet->{'activityData'}; foreach my $data (@$aktData) { ... }
my @aktData = @{ $aktivitaet->{'activityData'} }; foreach my $data (@aktData) { ... }

Edit: here's an example of why a list (...) within a hashref isn't what you want.

use Data::Dumper; my $data = { "list" => ( "foo", "bar", "baz" ), }; print Dumper($data);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-19 19:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found