anjiro has asked for the wisdom of the Perl Monks concerning the following question:
sub _setter_getter_maker { my $subname = shift; my $funcref; $funcref = eval<<"END"; sub { my(\$self, \$$subname) = \@_; \$self->{'$subname'} = \$$subname if defined \$$subname; return \$self->{'$subname'}; }; END return $funcref; }
The idea for use is basically thus:
my $pretend_object = {}; my $new_func = _setter_getter_maker($pretend_object, 'attrib'); #Now we can set a value for 'attrib' in this object $new_func->('value');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pretending to be lisp: macros
by Zaxo (Archbishop) on Sep 18, 2003 at 02:09 UTC | |
by anjiro (Beadle) on Sep 23, 2003 at 04:20 UTC | |
|
Re: Pretending to be lisp: macros
by simonm (Vicar) on Sep 18, 2003 at 04:13 UTC | |
|
Re: Pretending to be lisp: macros
by sgifford (Prior) on Sep 18, 2003 at 04:38 UTC | |
|
Re: Pretending to be lisp: macros
by Anonymous Monk on Sep 18, 2003 at 02:28 UTC | |
|
Re: Pretending to be lisp: macros
by adrianh (Chancellor) on Sep 18, 2003 at 10:26 UTC | |
|
Re: Pretending to be lisp: macros
by bsb (Priest) on Sep 19, 2003 at 03:52 UTC | |
by adrianh (Chancellor) on Sep 19, 2003 at 06:49 UTC | |
by diotalevi (Canon) on Sep 19, 2003 at 22:58 UTC |