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


in reply to Math::Vector - request for comments

Your last six methods could be consolidated:
no strict 'refs'; foreach my $axis ('i', 'j', 'k') { *{ $axis } = sub { my $self = shift; if (@_) { $self->{"_$axis"} = shift; } return $self->{"_$axis"}; } }
If you're willing to limit this to Perl 5.6 and newer, you could also look into lvaluable subroutines. Class::Accessor also handles much of the same thing for you nearly automagically.