in reply to Creating variables for each array member
#!/usr/bin/perl use warnings; use Tk; my $mw = tkinit; my %buttonhash; my @array = (0..5); for $i ( @array ) { $buttonhash{$i} = $mw->Button( -text => "Button $i", -command => [\&printme, $i], )->pack(); } my $reconbut = $mw->Button( -text => 'Reconfigure', -command => \&recon, )->pack(); MainLoop; sub printme { print "@_\n"; } sub recon{ foreach my $key (sort keys %buttonhash){ $buttonhash{$key}->configure(-text => 'Button '. ($key + 10)); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Creating variables for each array member
by GrandFather (Saint) on Jul 25, 2006 at 21:04 UTC | |
by zentara (Cardinal) on Jul 26, 2006 at 12:29 UTC |