I make an API call to a third party and the results are returned to me in a hash value that I named %hash.
When I print the results using Data::Dumper I get the following results:
print Dumper %hash;
$VAR1 = '';
$VAR2 = {
'Field1' => 'first result',
'Field2' => {},
'Field3' => 'random value',
'Field4' => {},
'Field5' => '102',
'Field6' => '3600176056428',
'Field7' => 'AhhRbwSXxIzaSZYuvgXE8AmAXUdy'
};
I’m not accustomed to Dumper returning two values. I printed the structure so that I could determine how to access the values it holds. I want to access the hash data structure in the second VAR ($VAR2). How exactly is this done?
$hash{‘Field2’} does not return any value (obviously).
You need to convert hash to hash reference:
Otherwise
%hashis converted into list of key => value pairs. That’s hash behavior in list context.To access values you’ll need to use following:
Because in fact you have hash of hashes.