What I am doing wrong combining the two scripts?
use Tk; my $mw = MainWindow->new(); { package Tie::Scalar::Callbacks; sub TIESCALAR { my $class = shift; my %self; @self{qw/ val store_cb fetch_cb /} = @_; return bless \%self, $class; } sub FETCH { my $self = shift; $self->{fetch_cb}->($self->{val}) if $self->{fetch_cb}; return $self->{val}; } sub STORE { my $self = shift; my $val = shift; $self->{store_cb}->($self->{val}, $val) if $self->{store_cb}; $self->{val} = $val; }; sub DESTROY { %{shift()}=() } } tie my $name, 'Tie::Scalar::Callbacks', "foo", sub { print "Entry value has changed!\n" }; my $label = $mw->Label( -text => 'Enter:', )->grid( -row => 0, -column => 0, ); my $entry = $mw->Entry( -textvariable => \$name )->grid( -row => 0, -column => 1, ); print "name is $name\n"; $name = "bar"; print "name is $name\n"; MainLoop;
(Note that I took away the button as I only a simulation of the third party component changing the scalar value)
In reply to Re^2: call subroutine if scalar is changed
by Anonymous Monk
in thread call subroutine if scalar is changed
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |