Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Add an arrayref to a hashref (diverehohy)

by Anonymous Monk
on Aug 13, 2019 at 04:27 UTC ( #11104368=note: print w/replies, xml ) Need Help??


in reply to Add an arrayref to a hashref

rehohy

my $Record = {}; $Record->{designation} = "Manager"; #d0 $Record->{name} = "Harsha"; #d0 $Record->{personal}[0] = "Country"; #d1 $Record->{personal}[1] = "location"; #d1 $Record->{personal}[2] = "language"; #d1

diverehohy

use Data::Diver qw/ DiveVal /; my $Record = {}; DiveVal( $Record, qw/ designation /) = "Manager"; #d0 DiveVal( $Record, qw/ name /) = "Harsha"; #d0 DiveVal( $Record, qw/ personal 0 /) = "Country"; #d1 DiveVal( $Record, qw/ personal 1 /) = "location"; #d1 DiveVal( $Record, qw/ personal 2 /) = "language"; #d1 #use Data::Dump qw/ dd /; #dd( $Record ); use JSON; print JSON->new->ascii(1)->pretty(1)->encode($Record); __END__ { "designation" : "Manager", "personal" : [ "Country", "location", "language" ], "name" : "Harsha" }

dd

my $Record = { designation => "Manager", name => "Harsha", personal => ["Country", "location", "language"], };

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2020-12-04 15:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (60 votes). Check out past polls.

    Notices?