use warnings; use strict; use Foo; use Bar; my $foo = new Foo; my $bar = new Bar($foo); $foo->x("from program"); print "(app) Memory: $foo, X: ".$foo->x()."\n"; $bar->show(); #### package Foo; sub new { my $name = shift; bless { x => 'from Foo' }, $name; } sub x { my ($self, $arg) = @_; $$self{x} = $arg if ($arg); return $$self{x}; } 1; #### package Bar; sub new { my $name = shift; my $foo = shift; bless { foo => $foo }, $name; } sub show { my $self = shift; my $foo = $$self{foo}; print "(bar) Memory: $foo, X: ".$foo->x()."\n"; } 1;