Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Loop through array of hashes

by jeffa (Bishop)
on Jan 21, 2016 at 18:51 UTC ( [id://1153312]=note: print w/replies, xml ) Need Help??


in reply to Loop through array of hashes

Why not use a function for that?

use strict; use warnings; my %foo = ( one => 1, two => 2 ); my %bar = ( three => 3, four => 4 ); my %baz = ( five => 5, six => 6 ); dump_keys( $_ ) for \%foo, \%bar, \%baz; sub dump_keys { print "$_\n" for keys %{+shift} }

Update: I am using ONE list without the need to wrap it in an array.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: Loop through array of hashes
by GotToBTru (Prior) on Jan 21, 2016 at 20:42 UTC

    It's that classic blunder, less well known than getting involved in a land war in Asia: use of numbered variables instead of an array! Especially when the OP calls for it.

    use strict; use warnings; my @aoh; push @aoh, { one => 1, two => 2 }; push @aoh, { three => 3, four => 4 }; push @aoh, { five => 5, six => 6 }; dump_keys( $_ ) for @aoh; sub dump_keys { print "$_\n" for keys %{+shift} }

    Update: jeffa has since revised his answer to make my comment irrelevant.

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

      Why don't you harass the other responses with your pedantry? Everyone in this post used numbered variables because the context was something else --- taking a reference. Please, learn how to read.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-20 02:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found