http://qs321.pair.com?node_id=642590


in reply to a simple matter of elegance

Hi,

I've not seen this suggested yet:

{ no strict qw(refs); foreach my $method ( keys %{ $self->{'data'} } ) { *{$method} = sub { my ( $self ) = @_; return $self->{'data'}->{$method}; }; } }
I've used this a few times in the past to generate repetitive object accessors/mutators.

Cheers, Tim

Update: I beg your pardon, snoopy beat me to it :-)