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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |