in reply to lazy creation of a hash

limit test access to the first pair of keys ordered by Perl internally, e.g.:
%h or $object -> init( \%h );
updated: "each" removed -- owing to comment from Moritz -- this becomes the code for my next idea, to allow Perl to optimise the test its own sweet way - seems likely to be optimised - I even doubt it's really needed to put "scalar" in front.

One world, one people

Replies are listed 'Best First'.
Re^2: lazy creation of a hash
by moritz (Cardinal) on May 12, 2011 at 13:31 UTC
    NOOO.
    my %foo = (a => 1, b => 2); for (1..10) { each %foo or print "re-init $_\n"; } __END__ re-init 3 re-init 6 re-init 9

    each uses an iterator tied to the variable. If you use it, you interfer with other (and even your own) usages of that iterator.

Re^2: lazy creation of a hash
by John M. Dlugosz (Monsignor) on May 13, 2011 at 01:10 UTC
    (re the modified form) Right, using it in boolean context allows it to know I really care only if it is empty or not, and don't need to count the actual values.