in reply to Re: How do I efficiently predeclare a hash with a set of keys
in thread How do I efficiently predeclare a hash with a set of keys

How does this compare, for speed and memory use, to
@set{ 5,6,8..53,62..106 } = ();
? I'd expect them to be comparable.

Replies are listed 'Best First'.
Re^3: How do I efficiently predeclare a hash with a set of keys
by BrowserUk (Patriarch) on May 19, 2007 at 10:07 UTC

    Good call. At some point in the past, the undef version used less memory and was faster than the null list assignment version. If I remember correctly, it was tilly that pointed this out to me.

    However, I just tried it with 5.8.8 and that is no longer the case. They both use the same amount of memory, and the null list assignment is marginally (~4%) faster. It's still faster and uses less memory than the typical method.

    my %set = map{ $_ => 1 } 1, 2, 5..8, 100..200;

    Another case of How do I know what I 'know' is right?. :( I'll update my node above to reflect this.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.