LivingDust has asked for the wisdom of the Perl Monks concerning the following question:
I have tried searching on this and find things close but nothing quite on the money for my problem.
As you see in the code below, I am using -textvariable and the variable is a element in a hash. I have set up four buttons. What I find is that
1: If I assign a whole new hash to the old hash, there is no change picked up and the display does not change. Why not? Is it throwing my old hash away and giving me the address to a new hash?
2: If I assign a scaler literal or a scaler variable to the hash element, it IS picked up and the display changes.
3: If I assign the elements of the hash in a loop from another hash it works.
#!/usr/bin/env perl use warnings; use strict; use Tk; our %FinalNoRecord = ( COMPANY_CODE => 'AB', COMPANY_NAME => 'ABC, Inc.', ); our %FinalNoRecord_change = ( COMPANY_CODE => 'XY', COMPANY_NAME => 'XYZ, Inc.', ); our $company_change = 'Foo, LLC.'; our $mw = MainWindow->new(); $mw->title("hashTkEntryTestcase"); my $topInfoFrm = $mw->LabFrame( -relief => 'groove', -borderwidth => 3, -label => "Final Assembly Information:", -labelside => 'acrosstop' )->pack(-side => 'top', -fill => 'both'); my $companyInfoFrm = $topInfoFrm->LabFrame( -label => "Company Code:", -labelside => 'left' )->pack(-side => 'top', -fill => 'x', -anchor => 'w'); my $companyCodeEntry = $companyInfoFrm->Entry( -width => 3, -textvariable => \$FinalNoRecord{COMPANY_CODE}, )->pack(-side => 'left'); my $companyNameEntry = $companyInfoFrm->LabEntry( -label => "Company Name:", -labelPack => [qw/-side left -anchor w/], -width => 30, -textvariable => \$FinalNoRecord{COMPANY_NAME}, -state => 'readonly', -relief => 'flat' )->pack(-side => 'left', -expand => 1, -anchor => 'w'); my $ChangeHashButton = $mw->Button( -text => "ChangeHash", # This doesn't work. -command => sub{%FinalNoRecord = %FinalNoRecord_change; } )->pack(-side=>'left'); my $ChangeCodeButton = $mw->Button( -text => "ChangeCode", # This does work. -command => sub{ $FinalNoRecord{COMPANY_CODE} = 'LM'; } )->pack(-side=>'left'); my $ChangeNameButton = $mw->Button( -text => "ChangeName", # This also works -command => sub{ $FinalNoRecord{COMPANY_NAME} = $company_change; } )->pack(-side=>'left'); my $ChangeHashLoopButton = $mw->Button( -text => "ChangeHashLoop", # This works too. -command => sub{ for my $key (keys %FinalNoRecord) { $FinalNoRecord{$key} = $FinalNoRecord_change{$key}; } } )->pack(-side=>'left'); my $ExitButton = $mw->Button( -text => "Exit", -command => [$mw=>'dest +roy'] )->pack(-side=>'right'); MainLoop();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: -textvariable won't update when using hash element
by GrandFather (Saint) on May 09, 2013 at 01:10 UTC | |
by LivingDust (Novice) on May 09, 2013 at 15:37 UTC | |
by GrandFather (Saint) on May 09, 2013 at 20:14 UTC | |
|
Re: -textvariable won't update when using hash element
by LivingDust (Novice) on May 09, 2013 at 00:13 UTC |