in reply to Re: Add an arrayref to a hashref
in thread Add an arrayref to a hashref

I was looking for this:
{ name => "Harsha", designation => "Manager", personal => ["Country", "location", "language"], }

I will have to convert into JSON after that, it should work. Thanks!

Replies are listed 'Best First'.
Re^3: Add an arrayref to a hashref
by 1nickt (Canon) on Aug 12, 2019 at 20:28 UTC

    To add to ++haukex's answer, if you want to add an item, dereference the array and push to it :

    push(@{ $href->{personal} }, 'birthday' );
    If you don't know the items before you build the aref and store in the href:
    push(@{ $href->{personal} }, $_) for @some_list;

    Hope this helps!


    The way forward always starts with a minimal test.