Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How to assign an array to a value in hash?

by periapt (Hermit)
on Apr 22, 2004 at 12:33 UTC ( [id://347327]=note: print w/replies, xml ) Need Help??


in reply to How to assign an array to a value in hash?

Your problem occurs in the mixed use of array and scalar values. The assignment $new_hash{$some_key1} = @some_array1 actually references @some_array1 in the scalar context (because $new_hash{$some_key1} is of the scalar data type). In the scalar context @some_array1 will simply return the number of elements in the array. If you want to save the actual array, assign a reference to the array into the hash such as $new_hash{$some_key1} = \@some_array1. This will preserve the array. You can now reference the elements of the array as $new_hash{$some_key1}[0], $new_hash{$some_key1}[1] etc

PJ

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-03-28 10:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found