I'm not sure about the best way to explain this, except to show by example:
use strict; my @array = ( 1, 2, 3, 4 ); print \@array,$/; my $ar0a = \$array[0]; @array = ( 5, 6, 7, 8 ); print \@array,$/; my $ar0b = \$array[0]; print "$ar0a :: $ar0b\n"; # will stringify memory address
When I run that (macosx, perl 5.8.1), I find that address of the array ("\@array") remains the same, but the two instances of $array[0] have different memory addresses.

Obviously, when you assign a scalar to  $array[$index] (given that this array element already has a value), you end up using the original memory address and overwriting the value that is stored there. When you assign a new list to the array, the act of instantiating a list (using the parens) on the rhs of the assignment involves allocating new memory to hold that list, and the lhs array now refers to that new allocation, instead of any previous one.

update: So, the way to make your Perl/Tk script do what you want is to always use a for loop to reset values in the array, so as to preserve the original memory addresses of the elements -- e.g. if you add these lines to the test case above, and print the address of element 0, you'll see that it doesn't change:

my $i = 0; $array[$i++] = $_ for ( 5, 6, 7, 8 );

In reply to Re: Perl/Tk and the "-variable => \$var" option by graff
in thread Perl/Tk and the "-variable => \$var" option by Mikster

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.