#!/usr/bin/perl -w use strict; use Tk; my @bit; tie @bit, 'Bitters'; my $mw = Tk::MainWindow->new(); my $entry = $mw->Label( -textvariable => \$Bitters::Concat, )-> pack( -expand => 'y', ); my $foo_button = $mw->Button( -text => "Bit One", -command => sub { flip( $bit[1] );} )->pack(); my $bar_button = $mw->Button( -text => "Bit Zero", -command => sub { flip( $bit[0] );} )->pack(); print "MainLoop\n"; MainLoop(); sub flip { $_[0] = ( $_[0] eq 'x' ) ? 'y' : 'x'; } { package Bitters; use vars qw( $Concat ); sub TIEARRAY { my $class = shift; my $self = { ARRAY => ['x','x'] }; bless $self, $class; $self->update_concatenation(); return $self; } sub FETCH { my($self,$idx) = @_; return $self->{ARRAY}[$idx]; } sub FETCHSIZE { my $self = shift; return $self->{ARRAY}+0; } sub STORESIZE { print "STORESIZE ignored\n"; } sub STORE { my($self, $idx, $value) = @_; print "[STORE $value at $idx]\n"; $self->{ARRAY}[$idx] = $value; $self->update_concatenation(); return $self->{ARRAY}[$idx]; } sub update_concatenation { my $self = shift; $Concat = $self->{ARRAY}[0] . $self->{ARRAY}[1]; print "$Concat\n"; } }#end_package Bitters;