in reply to Re: Convert string to hash
in thread Convert string to hash

just added the'\' and worked :)
foreach my $value (values $jsonhash{results} ) { $temp{$value->{'certname'}} = \%$value; }

Replies are listed 'Best First'.
Re^3: Convert string to hash
by AppleFritter (Vicar) on Mar 27, 2017 at 18:22 UTC

    That works, but it is unnecessary, since \ and % are complements, in a sense, and cancel each other out: % dereferences a hash reference ($value), i.e. gives you the hash it references; \ then gives you a reference to this hash again.

    There's nothing wrong with doing it this way, but I encourage you to get a good grip on references (hash or not). You'll often encounter them in Perl, and nested data structures don't work without them at all.

Re^3: Convert string to hash
by 1nickt (Canon) on Mar 27, 2017 at 18:21 UTC

    It's cheaper to throw away a % than to add a \ ...

    Your solution is silly. Read perlreftut to find out why ... worth your time!


    The way forward always starts with a minimal test.