in reply to Keys() required to autovivify?
In your first example, the enclosure within %{...} requires that the enclosed expression must yield a reference to a hash (not doing so is an error), and of course, undef cannot be interpreted as a hash ref.
In your second example, the "keys()" function is only looking at keys in the hash, not at values, so it doesn't matter that the "default value" being assigned to $h{x} happens to be undef.
UPDATE: When I first wrote and posted the above, it seems I was missing an important point, and I think GrandFather came closer to getting it right in his reply below: there is something "DWIM-ishly" odd going on with the keys() function, and I personally cannot explain why the second snippet in the OP does not trigger an error. On reflection, it strikes me as strange, and I understand jrw's continuing sense of confusion. (But ikegami and shmem have helped a lot with their replies, and I am less confused now.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Keys() required to autovivify?
by jrw (Monk) on Dec 30, 2007 at 07:56 UTC | |
by GrandFather (Saint) on Dec 30, 2007 at 10:14 UTC | |
by Anonymous Monk on Dec 30, 2007 at 14:14 UTC | |
by GrandFather (Saint) on Dec 30, 2007 at 20:31 UTC | |
by jrw (Monk) on Dec 30, 2007 at 23:59 UTC |