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


In reply to Re: How to connect more arrays to a new array by Abigail-II
in thread Find unique elements from multiple arrays by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.