Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Cannot use foreach on array of hashes

by BillKSmith (Monsignor)
on Dec 18, 2019 at 15:05 UTC ( [id://11110335]=note: print w/replies, xml ) Need Help??


in reply to Cannot use foreach on array of hashes

Data::Dumper expects either a scalar or reference variable (Refer: DESCRIPTION section of Data::Dumper). You should pass it a reference to you structure. Remember to interpret $VAR1 as a reference to your structure. Using hippo's example:
#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my @aktData = ([ { foo => 'bar' }, { foo => 'baz' } ]); #print 'Array: ' . Dumper (@aktData); print 'Array: ' . Dumper (\@aktData); foreach my $data (@aktData) { print 'Element: ' . Dumper ($data); } OUTPUT: Array: $VAR1 = [ [ { 'foo' => 'bar' }, { 'foo' => 'baz' } ] ]; Element: $VAR1 = [ { 'foo' => 'bar' }, { 'foo' => 'baz' } ];

The Dumper output clearly shows the problem he describes.

Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-24 10:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found