Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Hash value printing... WITH ARRAYS *dun dun dun*

by toolic (Bishop)
on Feb 06, 2012 at 22:49 UTC ( [id://952181]=note: print w/replies, xml ) Need Help??


in reply to Hash value printing... WITH ARRAYS *dun dun dun*

I think you really want a hash-of-arrays (see perldoc perldsc):
use warnings; use strict; my $primaryFeatures = { 'foo', ['fool', 'food', 'foot'], 'bar', ['barricade'], }; while (my ($key, $value) = each(%$primaryFeatures)){ print "($key, $_)\n" for @{ $value }; } __END__ (bar, barricade) (foo, fool) (foo, food) (foo, foot)

I used square brackets to construct the arrays, then I dereferenced the arrays in the while loop.

It is also customary to use fat commas (=>) when constructing hashes

my $primaryFeatures = { foo => ['fool', 'food', 'foot'], bar => ['barricade'], };

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-19 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found