Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Add an arrayref to a hashref

by BillKSmith (Monsignor)
on Aug 12, 2019 at 20:40 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11104354]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found