Why your code sub { selectAccount(+$i) } works?
And why my code sub { &selectAccount(+$i) } did not?
... I have always been using with the ampersand with binds.

Further to tybalt89's reply...
The  & (ampersand) has nothing to do with it. (Likewise the  + (plus) sign in front of the $i; I don't know where that came from.) The trick is to switch from your C-style  for (my $i=1; $i<200; $i++) { ... } loop to a Perl-style  for my $i (1..200) { ... } loop.

In the C-style loop, the variable  $i is defined once and given many values, the last of which is 200 (because that's the value that finally fails the  $i<200 test). All the  sub { selectAccount($i) } and  sub { markAccount($i) } expressions symbolicly reference (if that's the right term) this single  $i variable which has only one final value. At the end of the  InitializeListBox() routine, the referential bindings "close" over the single  $i variable (with its single value) because all symbolic references to the variable are used within code references which are passed to another subroutine, tag(), and must therefore persist. (Again, I may not have quite the right terminology here, but that's the general idea.)

In the Perl-style loop, the  $i variable is aliased to many different values. Each  sub { ... } expression symbolically references a different value via the  $i alias. All these different, individual values are then closed over. I think that's about right.

See closure.

As to your other, Tk-related questions, it's been a while since I've played with Tk very much and someone else could, I'm sure, give you much better answers with much less mental effort.

Update: Made a few minor changes to wording in the interest, I hope, of clarity.


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


In reply to Re^3: problem with TK, tag, passing param with binding, destroying binds by AnomalousMonk
in thread problem with TK, tag, passing param with binding, destroying binds by jsteng

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.