in reply to Updating Tk Entries with Hash
More usual in my code would be passing a reference to the "hash of button values" to the udating subroutine instead of using a globally scoped variable:sub LoadNewValues { @MyValues{qw(1 2 3)}=("hallo", "ok", "fine"); }
I am wondering about your use of "our"? i.e., our %MyValues=("1...")my $button1 = $mw->Button(-text => 'Update Values', -command => sub{ +LoadNewValues(\%MyValues)})->pack(); sub LoadNewValues { my $href = shift; $href->{1} = "hallo"; #hash slice syntax also possible $href->{2} = "ok"; $href->{3} = "fine"; }
An "our" variable goes into the global namespace. This is used for 2 main reasons: (a) To allow one separately compilied package to address a variable in another and (b) to allow "localization" of a variable, local $x;. Neither of these 2 things apply in your code.
I would not use an "our" variable when a "my" variable would suffice.
|
|---|