Depends on if my is used, doesn't it?

I went to check, and wrote this script:

#!/your/perl/here use strict; use warnings; use Data::Dumper; my @array = 0..4; print "\@array ", \@array, "\n"; print Dumper @array; my %hash; $hash{one} = \@array; print "\%hash x1\n"; print Dumper %hash; my @array = 'a'..'e'; print "\@array ", \@array, "\n"; print Dumper @array; $hash{two} = \@array; print "\%hash x2\n"; print Dumper %hash; print "";
Which gives this output:
c:\perl\perl>hash_array.pl "my" variable @array masks earlier declaration in same scope at C:\perl\perl\hash_array.pl line 16. @array ARRAY(0x1a452dc) $VAR1 = 0; $VAR2 = 1; $VAR3 = 2; $VAR4 = 3; $VAR5 = 4; %hash x1 $VAR1 = 'one'; $VAR2 = [ 0, 1, 2, 3, 4 ]; @array ARRAY(0x1ae73c8) $VAR1 = 'a'; $VAR2 = 'b'; $VAR3 = 'c'; $VAR4 = 'd'; $VAR5 = 'e'; %hash x2 $VAR1 = 'one'; $VAR2 = [ 0, 1, 2, 3, 4 ]; $VAR3 = 'two'; $VAR4 = [ 'a', 'b', 'c', 'd', 'e' ];
which differs from the debug x output at the end:
c:\perl\perl>perl -d hash_array.pl Loading DB routines from perl5db.pl version 1.19 Editor support available. Enter h or `h h' for help, or `perldoc perldebug' for more help. main::(hash_array.pl:7): my @array = 0..4; DB<1> c 24 [snip Dumper output] main::(hash_array.pl:24): print ""; DB<2> x \%hash 0 HASH(0x1c23ca4) 'one' => ARRAY(0x1c1b9ac) 0 0 1 1 2 2 3 3 4 4 'two' => ARRAY(0x1c1b9ac) -> REUSED_ADDRESS
But if I enclose the last my @array... in a block, the debugger gives the same answer (and the compiler warning goes away).

Any hints?

-QM
--
Quantum Mechanics: The dreams stuff is made of


In reply to Re:^5: A hash of lists by QM
in thread A hash of lists by wolis

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.