ActiveState perl 5.10.0 (Binary build 1004 287188)
Quick and messy, but here are some examples: (works)
#!/usr/bin/perl use Win32::GUI; my $w = 800; my $h = 800; my $i; $main = Win32::GUI::Window->new( -name => 'main', -width => $w, -height => $h, -menu => $menu, ); $main->AddButton( -height => 20, -width => 100, -text => 'Go!', -name => 'execute', -top => 20, -left => 650, -tabstop => 1, ); $main->Show(); Win32::GUI::Dialog(); sub another_sub { $top = 50; for ($x = 0; $x <= 2; $x++) { $uniqueWindow[$i] = $main->AddTextfield( -height => 200, -width => $w-30, -background => [255,255,255], -top => $top, -left => 10, -text => "", -name => $i."Textfield", -align => left, -readonly => 1, -multiline => 1, -autovscroll => 1, -vscroll => 1, ); $uniqueWindow[$i]->SetLimitText(1000); $top+=205; $i++; } } sub execute_Click { another_sub(); foreach $j (0..$i-1) { $SUB = $j."Textfield_MaxText"; print "-->Assigning sub function for $j\n"; my $idx = $j; # make a copy my $SUB = "${idx}Textfield_MaxText"; *$SUB = sub { variableMaxText( $idx ); } } for ($x=0;$x<100;$x++) { foreach my $txt (0..$i-1) { $uniqueWindow[$txt]->Append("Characters to make it overflo +w"); } } } sub variableMaxText { my ($self) = $_[0]; print "Variable window got maxtexted ($self).\n"; $uniqueWindow[$self]->Text(""); }
And I think it should, but it doesn't (minor change, didn't include everything)
foreach $j (0..$i-1) { $SUB = $j."Textfield_MaxText"; print "-->Assigning sub function for $j\n"; my $SUB = "${idx}Textfield_MaxText"; *$SUB = sub { variableMaxText( $j ); } }
Output from the success:
-->Assigning sub function for 0 -->Assigning sub function for 1 -->Assigning sub function for 2 Variable window got maxtexted (1). Variable window got maxtexted (2). Variable window got maxtexted (1). Variable window got maxtexted (2).
Output from the failure:
-->Assigning sub function for 0 -->Assigning sub function for 1 -->Assigning sub function for 2 Variable window got maxtexted (). Variable window got maxtexted ().
And if we get crazy and assign my $j where I define my $i:
-->Assigning sub function for 0 -->Assigning sub function for 1 -->Assigning sub function for 2 Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2). Variable window got maxtexted (2).

In reply to Re^4: Global vs. local? by jpavel
in thread Global vs. local? by jpavel

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.