http://www.perlmonks.org?node_id=617883


in reply to Re: [Perl 6] Any provision for a "dereferencing object"?
in thread [Perl 6] Any provision for a "dereferencing object"?

In perl5, what about something like...
my $a = []; $a->[1]{bar}{baz}[3] = 7; bless $a, "hrmph"; *hrmph::deref = sub { $_[0]->[1]{bar}{baz}[3] }; print "yeah: ", $a->deref, "\n";

It's maybe not the clearest or most maintainable thing in the whole wide world, but it's not "impossible." You could even build on it to make it more readable, reliable, and more flexible in various ways.

(UPDATE: I clicked the wrong reply button, so if there's a kind editor that could move me up a level?)

UPDATE: Oh, I see what you're up to I think. Some function you build once and applicate anwhere. I am also a little surprised your $x->$deref.

-Paul