in reply to Keys() required to autovivify?
Your code is overly complicated. $h{$x} can be replaced with just $h.
>perl -le"%{ $h }; print $h ? 1 : 0" 0 >perl -le"%{ $h } = (); print $h ? 1 : 0" 1 >perl -le"keys %{ $h }; print $h ? 1 : 0" 1 >perl -le"sub {}->( %{ $h } ); print $h ? 1 : 0" 1
In the first program, the hash isn't required, so it isn't created.
In the subsequent programs, a hash is required, so it is autovivified.
I can't explain why some built-ins don't autovivify the hash, even though it needs to be flattened.
>perl -le"sub f {} f( %{ $h } ); print $h ? 1 : 0" 1 >perl -le"print( %{ $h } ); print $h ? 1 : 0" 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Keys() required to autovivify?
by jrw (Monk) on Dec 30, 2007 at 07:52 UTC | |
by shmem (Chancellor) on Dec 30, 2007 at 10:26 UTC | |
by Anonymous Monk on Dec 30, 2007 at 14:12 UTC | |
by shmem (Chancellor) on Dec 30, 2007 at 19:03 UTC | |
by jrw (Monk) on Dec 30, 2007 at 23:39 UTC | |
| |
|
Re^2: Keys() required to autovivify?
by shmem (Chancellor) on Jan 02, 2008 at 14:52 UTC | |
by ikegami (Patriarch) on Jan 03, 2008 at 14:02 UTC | |
by shmem (Chancellor) on Jan 03, 2008 at 14:19 UTC |