Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: one hash value (array) into another

by Enlil (Parson)
on Jan 06, 2004 at 18:25 UTC ( #319192=note: print w/replies, xml ) Need Help??


in reply to one hash value (array) into another

Really close.

What your hash ends up looking like is:

%hash = ( 'one' => [ 'abc', 'def', 'ghi' ], 'two' => 3 );

This is because $hash{'two'} is being assigned the length of the array held in $hash{'one'}. (in the same way that $array_size = @array would assign $array_size the length of @array)

What I assuming you want is a hash that ends up like:

%hash = ( 'one' => [ 'abc', 'def', 'ghi' ], 'two' => [ 'abc', 'def', 'ghi' ] );
which can be accomplished by something like so:
$hash{'two'} = [ @{$hash{'one'}} ];

-enlil

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2021-08-05 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (44 votes). Check out past polls.

    Notices?