in reply to Proper Way to Reference a Hash Value

rehohy

$VAR1->{content}{errors}[0]{field} = "merge_fields"; #d3 $VAR1->{content}{errors}[0]{message} = "This value should be of type object."; #d3

diverehohy

use Data::Diver qw/ DiveVal /; my $VAR1 = {}; DiveVal( $VAR1, qw/ content errors 0 field /) = "merge_fields"; #d3 DiveVal( $VAR1, qw/ content errors 0 message /) = "This value should be of type object."; #d3

Put it into practice without autovivification ;) Data::Diver

#!/usr/bin/perl -- use strict; use warnings; my $VAR1 = { 'cookies' => { '_AVESTA_ENVIRONMENT' => 'prod', '_mcid' = +> '1.340667ccb3eb6552450356561ab6bd92.4410ca7570d70e1141356a24d924a2a +789d1bea2b8a417b761406f755ab1d9ba' }, 'error' => '400 Bad Request', ' +content' => { 'detail' => 'The resource submitted could not be valida +ted. For field-specific details, see the \'errors\' array.', 'errors' + => [ { 'message' => 'This value should be of type object.', 'field' +=> 'merge_fields' } ], 'status' => 400, 'title' => 'Invalid Resource' +, 'type' => 'http://developer.mailchimp.com/documentation/mailchimp/g +uides/error-glossary/', 'instance' => '59edf1fc-ed93-4a40-ba23-1f0af2 +4a6eb3' }, 'raw' => '{"type":"http://developer.mailchimp.com/document +ation/mailchimp/guides/error-glossary/","title":"Invalid Resource","s +tatus":400,"detail":"The resource submitted could not be validated. F +or field-specific details, see the \'errors\' array.","instance":"59e +df1fc-ed93-4a40-ba23-1f0af24a6eb3","errors":[{"field":"merge_fields", +"message":"This value should be of type object."}]}', 'code' => '400' +, 'header' => { 'Server' => 'openresty', 'Client-SSL-Cipher' => 'ECDH +E-RSA-AES256-GCM-SHA384', 'Client-Date' => 'Mon, 27 Jan 2020 18:37:43 + GMT', 'Date' => 'Mon, 27 Jan 2020 18:37:43 GMT', 'Client-SSL-Cert-Is +suer' => '/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=GeoTrust RSA CA + 2018', 'Connection' => 'close', 'Client-Peer' => '23.55.203.69:443', + 'Content-Length' => '373', 'Client-SSL-Socket-Class' => 'IO::Socket: +:SSL', 'Content-Type' => 'application/problem+json; charset=utf-8', ' +X-Request-Id' => '59edf1fc-ed93-4a40-ba23-1f0af24a6eb3', 'Set-Cookie' + => '_AVESTA_ENVIRONMENT=prod; path=/, _mcid=1.340667ccb3eb6552450356 +561ab6bd92.4410ca7570d70e1141356a24d924a2a789d1bea2b8a417b761406f755a +b1d9ba; expires=Tue, 26-Jan-2021 18:37:42 GMT; Max-Age=31536000; path +=/; domain=.mailchimp.com', 'Client-SSL-Cert-Subject' => '/C=US/ST=Ge +orgia/L=Atlanta/O=The Rocket Science Group, LLC/OU=IT/CN=*.api.mailch +imp.com', 'Link' => '; rel="describedBy"', 'Client-Response-Num' => 1 + } }; use Data::Dump qw/ dd /; use Data::Diver qw/ Dive /; if( my $con = Dive( $VAR1, qw/ content /) ){ dd( $con ); if( my $errors = Dive( $con, qw/ errors /) ){ dd( $errors ); for my $error ( @$errors ){ dd( $error ); } } } dd( Dive( $VAR1, qw/ content errors 0 message /) ); __END__ { detail => "The resource submitted could not be validated. For fiel +d-specific details, see the 'errors' array.", errors => [ { field => "merge_fields", message => "This value should be of type object.", }, ], instance => "59edf1fc-ed93-4a40-ba23-1f0af24a6eb3", status => 400, title => "Invalid Resource", type => "http://developer.mailchimp.com/documentation/mailchimp/ +guides/error-glossary/", } [ { field => "merge_fields", message => "This value should be of type object.", }, ] { field => "merge_fields", message => "This value should be of type object.", } "This value should be of type object."