in reply to Non existent Hash and error"not a hash refernece at perl line"
If you're getting a message about it not being a hash reference, then it means you have something in the slot, but it's not a hash reference. You can check whether a hash slot exists with the perldoc -f exists. Here's a simple bit showing how to check several things out about a hash:
$ cat foo.pl use strict; use warnings; my %hash = ( foo => undef, bar => { a=>7 }, baz => 'quandary', ); for my $k ('joe', 'foo', 'bar', 'baz') { if (! exists $hash{$k}) { print "Key $k does not exist in hash\n"; next; } if (! defined $hash{$k}) { print "Key $k exists, but value is not defined\n"; next; } my $r = ref($hash{$k}); $r = "SCALAR" if $r eq ''; print "Key $k exists, refers to ", $r, "\n"; print "looking up \$hash{$k}{a}: $hash{$k}{a}\n"; } Roboticus@Waubli ~ $ perl foo.pl Key joe does not exist in hash Key foo exists, but value is not defined Key bar exists, refers to HASH looking up $hash{bar}{a}: 7 Key baz exists, refers to SCALAR Can't use string ("quandary") as a HASH ref while "strict refs" in use + at foo.pl line 22.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|