in reply to Re^4: Using variable contents in new variable name
in thread Using variable contents in new variable name
A more fully worked example may help:
use strict; use Tk; my @booths; my $mw = MainWindow -> new; for (0..5) { $booths[$_]{button} = $mw->Button ( -text => "Booth $_", -command => [\&Vote, \@booths, $_] )->pack (); } $mw->Button (-text => 'Done', -command => sub {$mw->destroy ()})->pack + (); MainLoop; sub Vote { my ($boothsRef, $boothNum) = @_; my $count = ++$boothsRef->[$boothNum]{count}; $boothsRef->[$boothNum]{button}->configure (-text => "Booth $booth +Num ($count)"); }
Note that the thing passed in is actually an array, but it could be a HoH or any other suitable structure.
|
|---|