Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: How to use hash of arrays

by saskaqueer (Friar)
on Feb 15, 2005 at 21:24 UTC ( [id://431339]=note: print w/replies, xml ) Need Help??


in reply to How to use hash of arrays

You are close, but off by a little. The code @$Hash{ArrayInHash} translates into @{$Hash}{ArrayInHash}, which is definitely not what you want; what you need is @{ $Hash{ArrayInHash} }. So you'd update your code as follows:

%Hash = ( ArrayInHash => [1,2,3,4], ); print "Array in hash: @{$Hash{ArrayInHash}}"; @Array = @{$Hash{ArrayInHash}}; print "\nArray: @Array"; $ArrayRef = $Hash{ArrayInHash}; @Array2 = @$ArrayRef; print "\nArray from ordinary scalar reference: @Array2"; print "\n\nTrying a foreach loop with the hash"; foreach(@{$Hash{ArrayInHash}}) { print "\n$_"; } print "\n\nTrying a foreach loop with the scalar array reference"; foreach(@$ArrayRef) { print "\n$_"; }

Replies are listed 'Best First'.
Re^2: How to use hash of arrays
by iKnowNothing (Scribe) on Feb 16, 2005 at 01:32 UTC
    Awesome! Thanks for the help!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-24 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found