in reply to Keys() required to autovivify?

From an internals point of view, they are different because keys() gives its operand deref-hv context, but a plain scalar context hash deref doesn't.

Nobody said this stuff was consistent! :)

Though I could argue that keys() is a write operation (it resets the hash iterator), and write operations should autovivify while read operations should not.

Replies are listed 'Best First'.
Re^2: Keys() required to autovivify?
by jrw (Monk) on Dec 31, 2007 at 04:42 UTC
    Thanks! I think this is the answer I was looking for. Keys() is supplying some extra magic to cause autovivification whereas plain scalar context unfortunately doesn't. Oh well. Unfortunately, I bet on if (%{$h{x}}) autovivifying because I knew if (keys %{$h{x}}) did.