First, I agree with the post from
AnomalousMonk.
The problem
that you are having relates to referants (references).
The OP'ed code will
work with this modification to LoadNewValues() subroutine:
sub LoadNewValues
{
@MyValues{qw(1 2 3)}=("hallo", "ok", "fine");
}
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:
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";
}
I am wondering about your use of "our"? i.e.,
our %MyValues=("1...")
I don't know what you think this does or why you used it. However,
in this example, there is no reason to do that at all. A "normal" lexically
scoped "my" variable at the highest level will also have global scope.
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.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.