Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Add an arrayref to a hashref

by BillKSmith (Prior)
on Aug 12, 2019 at 20:40 UTC ( #11104354=note: print w/replies, xml ) Need Help??


in reply to Add an arrayref to a hashref

I assume that you want to add the key "personal" to the hash and use the arrayref as the associated value. Refer to section "Using References' of perlref. The paragraph which begins "Anywhere you'd put an identifier..." always works.
use strict; use warnings; use Data::Dumper; my $arrayref = [ 'Country', 'location', 'language' ]; my $hashref = { 'name' => "Harsha", 'designation' => "Manager" }; ${$hashref}{personal} = $arrayref; print Dumper($hashref);

OUTPUT

$VAR1 = { 'name' => 'Harsha', 'designation' => 'Manager', 'personel' => [ 'Country', 'location', 'language' ] };
Bill

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2020-11-30 14:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?