Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Not a HASH reference

Tags:

hash

perl

I have pieve of code that I am trying to assign the return value but I see the following error. Appreciate if someone can let me know why am I getting this error.

Error: Not a HASH reference at line

sub getid {
   my ($a, $b) = @_;
   my $id = 1 << $a + 1 << $b;
   return $id;
}

my $tip;
$tip->{'tock'}->[0]->{'brick'} = getid(2, 3);  <== This is where I am having issue.
like image 416
Sreeram Ravinoothala Avatar asked Apr 19 '26 11:04

Sreeram Ravinoothala


1 Answers

That's not the code you actually ran to get that error. In your actual code, $tip or $tip->{'tock'}->[0] is defined but doesn't hold a reference to a hash. Print them out to find out which.

It might be useful to dump your data structure to figure out what it actually is.

use Data::Dumper;
print(Dumper($tip));
like image 52
ikegami Avatar answered Apr 22 '26 00:04

ikegami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!