sub onTick { our $x; # Initialize and associate $x with some external value foreach (@kabluther) { $x $_->getSkookiness(); } return $x; } #### sub onTick { our $x; # Initialize and associate $x with some external value foreach (@kabluther) { $_->getSkookiness( \$x ); } return $x; } #### #! perl -slw use strict; package proxy; my %flags; sub TIESCALAR { my $self = bless \$_[1], $_[0]; $flags{ $self } = 0; $self } sub FETCH { $flags{ $_[ 0 ] } |= 1; $_[0]; } sub STORE { $flags{ $_[ 0 ] } |= 2; ${ $_[0] } = $_[1]; } sub referenced { return ' :was read' if $flags{ $_[ 0 ] } == 1; return ' :was written' if $flags{ $_[ 0 ] } == 2; return ' :was read and written' if $flags{ $_[ 0 ] } == 3; return ' :was untouched'; } package main; sub readOnly { my $copy = $_[0] } sub writeOnly{ $_[ 0 ] = 'written'; } sub readThenWrite { my $copy = $_[0]; $_[ 0 ] = 'read & written'; } our $x = 'some text'; my $o = tie my $proxy, 'proxy', $x; print $x, $o->referenced; readOnly $proxy; print $x, $o->referenced; writeOnly $proxy; print $x, $o->referenced; readThenWrite $proxy; print $x, $o->referenced; __END__ c:\test>tieProxy some text :was untouched some text :was read written :was read and written read & written :was read and written