package TEST; use strict; ############################################## # # A generic object with fields specified # at creation time. # ############################################## my %data; sub new { my $self = bless [], shift; my @required_fields = @_; foreach my $field (@required_fields) { chomp $field; my $eval = "sub $field : lvalue { \$data{+shift}->{$field}; }"; eval $eval; } return $self; } sub DESTROY { delete $data{+shift}; } 1;