The problem is that the -textvariable parameter is taking a reference to the value in the hash - you know that of course, but there is a trap. When you assign the new hash to the old hash you are replacing the contents of the old hash, both keys and values, and most likely the values end up stored in a different place so the original reference isn't doing you any good any more. As an illustration of what's going on consider:

#!/usr/bin/env perl use warnings; use strict; my %fnr = ( COMPANY_CODE => 'AB', COMPANY_NAME => 'ABC, Inc.', ); my %fnr_loop = ( COMPANY_CODE => 'XY', COMPANY_NAME => 'XYZ, Inc.', ); my %fnr_but = ( COMPANY_CODE => 'PQ', COMPANY_NAME => 'PQR, Inc.', ); my $nameRef = \$fnr{COMPANY_CODE}; show('Original'); changeHashLoop(); show('Loop'); changeHashButton(); show('Button'); sub changeHashButton { %fnr = %fnr_but; } sub changeHashLoop { for my $key (keys %fnr) { $fnr{$key} = $fnr_loop{$key}; } } sub show { my ($label) = @_; my $ccRef = \$fnr{COMPANY_CODE}; printf "%8s: %s (%s) FNR: %s (%s)\n", $label, $$nameRef, $nameRef, $$ccRef, $ccRef; }

Prints:

Original: AB (SCALAR(0x94a554)) FNR: AB (SCALAR(0x94a554)) Loop: XY (SCALAR(0x94a554)) FNR: XY (SCALAR(0x94a554)) Button: XY (SCALAR(0x94a554)) FNR: PQ (SCALAR(0x94a584))

Note the change in the address of the FNR value when the hash copy has been made.

True laziness is hard work

In reply to Re: -textvariable won't update when using hash element by GrandFather
in thread -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.