http://www.perlmonks.org?node_id=1104672

GayathriBalu has asked for the wisdom of the Perl Monks concerning the following question:

hi all, i want to create an array of buttons and handle them when clicked. in my code the last button in the array is handled even if any other button is clicked. pls help. thanks

my @buttons; for my $i(0..5){ push @buttons, $mw->Button(-text => $i, -command => sub{ print "pressed $i\n"; # or use the widget: print "pressed ", $buttons[$i]->cget('-text'), "\n"; })->pack; }