in reply to Re: Re: How to connect more arrays to a new array
in thread Find unique elements from multiple arrays

Cute. It starts happening in 5.005_52, and ceases to happen in 5.7.1. And it only happens if you run the "my %h" at least twice, otherwise, it returns the same as the localized version.

My guess is that it is related to Perl not completely throwing away a lexical variable if it goes out of scope, because you often reenter a block and it's faster to keep the structure around. Look at this:

my @a = 1 .. 10; my @b = 5 .. 15; my @c = 10 .. 20; my @d = 15 .. 25; for (1 .. 2) { @B = do {local %h; $h {$a [0]} ++; print "B: ", scalar %h, "\n"; ++@h {@a, @b, @c, @d}; keys %h}; @C = do { my %h; $h {$a [0]} ++; print "C: ", scalar %h, "\n"; ++@h {@a, @b, @c, @d}; keys %h}; } __END__ B: 1/8 C: 1/8 B: 1/8 C: 1/32

The second time it's executing the my %h block, the hash already has 32 buckets.

Abigail

Replies are listed 'Best First'.
Re: Re: How to connect more arrays to a new array
by BrowserUk (Patriarch) on Apr 28, 2003 at 13:49 UTC

    Strange indeed. I wonder if it was deliberately fixed in 5.8 or whether that was when the new hashing algorithm came into effect?

    However did you discover the 2 runs effect?


    Examine what is said, not who speaks.
    1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
    2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
    3) Any sufficiently advanced technology is indistinguishable from magic.
    Arthur C. Clarke.
      However did you discover the 2 runs effect?

      Because I always want to minimize a program showing a particular effect, to further pinpoint what causes it. Your example used Benchmark, which runs the code several times. So, I first got rid of that, running each piece of code once, resulting in identical output. The next step was running it twice.

      Abigail