- or download this
package Person;
use strict;
...
NAME => undef,
AGE => undef
};
- or download this
my $closure = sub {
my $field = shift;
@_ and $self->{$field} = shift;
$self->{$field};
};
- or download this
bless $closure, $class;
$closure;
}
- or download this
sub name { &{ $_[0] }("NAME", @_[1 .. $#_ ] ) }
sub age { &{ $_[0] }("AGE", @_[1 .. $#_ ] ) }
- or download this
use strict;
use Person;
...
$person->age(22);
print $person->name, " is ", $person->age, " years old.\n";