in reply to declaring accessor methods from a list

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.

Replies are listed 'Best First'.
Re^2: declaring accessor methods from a list
by Bro. Doug (Monk) on Apr 26, 2007 at 22:53 UTC
    Thank you.

    I tried that and it worked. And yes, I could be looking for prior art. I'm also just interested in knowing how this thing is done (a perlmonks party trick?).

    After I get this working and tested from a test.pl, I'll post it up with corrections.

    Peace monks,
    Bro. Doug :wq
      perlmonks is full of prior art