in reply to Implementing a Data Cache
I am trying to get it so that the output will look like this instead:
You'll need another layer of reference. Study the following and you'll understand, I think:
#!/usr/bin/perl -w use diagnostics; use strict; { my $cache = [\Foo->new]; # Additional reference sub access_cache { return @$cache; } } # Additional dereferencing required too. 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]};
That produces the output you are looking for.
-sauoq "My two cents aren't worth a dime.";
|
|---|