sub $name {} isn't working the way you expect it to because named subs are picked up during the compilation of the BEGIN block.
What you want to do is edit the GLOB with the name of your accessor in a fasion similar to this:
BEGIN { my @accessors = qw(one two foo); foreach my $methname (@accessors) { no strict 'refs'; *$methname = sub { # accessor sub }; } }
As an alternative to rolling your own autogenerator you could look on the CPAN as there are several mentioned elsewhere in this thread.
In reply to Re: declaring accessor methods from a list
by Trizor
in thread declaring accessor methods from a list
by Bro. Doug
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |