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();

In reply to -textvariable won't update when using hash element by LivingDust

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.