zealot has asked for the wisdom of the Perl Monks concerning the following question:
The output of this program is:#!/usr/bin/perl -w use diagnostics; use strict; { my $cache = [Foo->new]; sub access_cache { return @$cache; } } foreach (&access_cache()) { print "before: ", ref($_), "\n"; print "object: ", $_, "\n"; print "after: ", ref($_), "\n"; print "\n"; } foreach (&access_cache()) { print "before: ", ref($_), "\n"; print "object: ", $_, "\n"; print "after: ", ref($_), "\n"; print "\n"; } package Foo; sub new {bless [], $_[0]}; use overload '""' => sub {$_[0] = Bar->new; return $_[0]->[0]}; package Bar; sub new {bless ['barbar'], $_[0]}; use overload '""' => sub {return $_[0]->[0]};
I am trying to get it so that the output will look like this instead:before: Foo object: barbar after: Bar before: Foo object: barbar after: Bar
I am using This is perl, version 5.005_03 built for i386-freebsd.before: Foo object: barbar after: Bar before: Bar object: barbar after: Bar
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Implementing a Data Cache
by sauoq (Abbot) on Jul 09, 2003 at 02:38 UTC | |
|
Re: Implementing a Data Cache
by leriksen (Curate) on Jul 09, 2003 at 04:46 UTC | |
by sauoq (Abbot) on Jul 09, 2003 at 22:18 UTC | |
by zealot (Sexton) on Jul 09, 2003 at 18:41 UTC |