Part of my confusion seems to boil down to the following:
All of you write my hash structures like this
and as I understand the two following notations are equivalentif (not exists $coordinates->{$group}{$id}{$stage}{"coords"}) {
All three work, they are dereferencing the hash reference $coordinates and provide the hash reference of the anonymous subhash that has at its top level the coordinate numbers as keys.if (not exists ${$coordinates}{$group}{$id}{$stage}{"coords"}) { if (not exists ${${${${$coordinates}{$group}}{$id}}{$stage}}{"coords"} +)
The following tests for the $coordinates-> notation also go through without error:
However, what about %{$$coordinates{$group}{$id}{$stage}{"coords"}}that is used inif (not defined $coordinates->{$group}{$id}{$stage}{"coords"}) { if (!($coordinates->{$group}{$id}{$stage}{"coords"})) {
I always thought this is equivalent and also would give the hash reference of the anonymous subhash? Butforeach my $coord_no (keys %{$$coordinates{$group}{$id}{$stage}{"coord +s"}}) {…}
Thus, what does it return? And why is what it returns defined and true, but does not exist:if (not exists %{$$coordinates{$group}{$id}{$stage}{"coords"}}) { exists argument is not a HASH or ARRAY element
both go through just fine.if (not defined %{$$coordinates{$group}{$id}{$stage}{"coords"}}) { if (!(%{$$coordinates{$group}{$id}{$stage}{"coords"}})) {
To make my confusion complete, tests of a similar hash give different results:
Mmh.if (not exists %{$$original_data{$group}{$id}{$stage}}) { # exists argument is not a HASH or ARRAY element if (not defined %{$$original_data{$group}{$id}{$stage}}) { # works if (!(%{$$original_data{$group}{$id}{$stage}})) { # Can't use an undefined value as a HASH reference
In reply to Re: Test if a subhash in a referenced hash exists
by Henri
in thread Test if a subhash in a referenced hash exists
by Henri
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |