Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I need to know if a given key equals a value or is a hash ref. The following code performs the check that I need, but only if strict is turned off:my %hash = ('one' => 1, 'two' => {'one' => 1, 'two' => {'one' => 1, 'two' => 2, 'three' => 3}}, 'three' => 1);
When Strict is being used it yields the following error, "Can't use string ("1") as a HASH ref while "strict refs" in use." What would be the best way to do this and leave strict enabled?if ((keys %{$hash{'one'}})) { print "Yes\n"; } else { print "No\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing for hash key value
by djantzen (Priest) on May 26, 2003 at 02:28 UTC | |
|
Re: Testing for hash key value
by jepri (Parson) on May 26, 2003 at 02:25 UTC |