On Wed, Nov 17, 2004 at 11:00:17AM -0500, Dave Gray wrote: > Charles K. Clarkson <[EMAIL PROTECTED]> wrote: > > [snip] > > : : foreach my $method ( keys %InheritableClassData ) { > > : : no strict 'refs'; > > : : *$method = sub { > > : : shift; > > : : $InheritableClassData{$_} = shift if @_; > > : : return $InheritableClassData{$_}; > > : : }; > > : : } > > [snip] > > Perhaps it's just me, but I find the following approach to be clearer > for generating accessors: > > ==CODE== > #!/usr/bin/perl > use strict; > use warnings; > > package test; > > our %InheritableClassData; > for my $aa (qw/aa bb cc/) { > eval qq( > sub $aa { > shift; > \$InheritableClassData{$aa} = shift if [EMAIL PROTECTED]; > return \$InheritableClassData{$aa}; > } > ); > }
Downsides: - all those ugly backslashes - you don't see your errors or warnings until runtime - and only then if you check $@ - and they'll look like "at (eval x) line y" which will leave you wondering which eval is x and then which line is y - you'll have similar problems when you come to use various tools such as profilers or code coverage analysers Upsides: - you don't have to turn off strict refs - you don't have to learn about globs -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>