This is probably an easy question but I can’t figure it out. I have a structure that is returned from a routine that, when I print with Data::Dumper, looks like
$VAR1 = {
'date' => 'May 15, 2012',
'value' => '0.20'
};
But I can’t get the data out of it. If I try $data{value} I get nothing. I am not that familiar with Perl. Can anyone help me? What am I missing?
Your
$VAR1is a hash ref, not just a hash. So you need to dereference the variable to get at the data:This is Perl, so TMTOWTDI (There’s More Than One Way To Do It):
However, the explicit
->arrow operator is generally easier to understand; the operand on the left is a reference, and the bit on the right accesses it ($hash->[0]for an array ref;$hash->{item}for a hash ref).You could use instead:
Now you can write:
(I could have used both
%VAR1and$VAR1; they’re distinct variables — but that’s extra confusing.)