in reply to A Lazy Class
package Tie::Scalar::Lazy; # usage: # use Tie::Scalar::Lazy; # lazy $value => \&expensive_function; require Exporter; @ISA = qw( Exporter ); @EXPORT = qw( lazy ); sub lazy { tie $_[0], __PACKAGE__, \$_[0], $_[1]; } sub TIESCALAR { my ($class, $sref, $cref) = @_; bless [ $sref, $cref ], $class; } sub FETCH { my $self = shift; my $value = $self->[1]->(); untie ${ $self->[0] }; ${ $self->[0] } = $value; } 1;
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker, who'd like a (from-home) job
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: A Lazy Class
by chip (Curate) on Apr 22, 2002 at 02:45 UTC | |
by japhy (Canon) on Apr 22, 2002 at 02:47 UTC |