... the address of another instance of the @Array_Vals array which has now been overwritten.

No. Each lexical variable created in the scope of the for-loop is independent of all the others; it has an independent address. Confirm this for yourself by looking (as Corion suggested) at these referenced arrays with Data::Dumper or some similar utility (I like Data::Dump).

c:\@Work\Perl\monks>perl -wMstrict -MData::Dumper -le "my @source = qw(a b c foo bar baz fee fie foe); ;; my @Array_of_ALL_Vals; ;; for my $iloop (0 .. 3){ my @Array_Vals; @Array_Vals = @source[ 0 .. rand @source ]; push @Array_of_ALL_Vals,\@Array_Vals; print Dumper \@Array_of_ALL_Vals; } ;; print '-----------'; print Dumper \@Array_of_ALL_Vals; " $VAR1 = [ [ 'a', 'b', 'c', 'foo', 'bar' ] ]; $VAR1 = [ [ 'a', 'b', 'c', 'foo', 'bar' ], [ 'a', 'b', 'c' ] ]; $VAR1 = [ [ 'a', 'b', 'c', 'foo', 'bar' ], [ 'a', 'b', 'c' ], [ 'a', 'b', 'c', 'foo' ] ]; $VAR1 = [ [ 'a', 'b', 'c', 'foo', 'bar' ], [ 'a', 'b', 'c' ], [ 'a', 'b', 'c', 'foo' ], [ 'a', 'b', 'c', 'foo', 'bar', 'baz', 'fee' ] ]; ----------- $VAR1 = [ [ 'a', 'b', 'c', 'foo', 'bar' ], [ 'a', 'b', 'c' ], [ 'a', 'b', 'c', 'foo' ], [ 'a', 'b', 'c', 'foo', 'bar', 'baz', 'fee' ] ];


Give a man a fish:  <%-{-{-{-<


In reply to Re^5: declare my variable in loop by AnomalousMonk
in thread declare my variable in loop by gauss76

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.