What do you find wrong or strange in this Perl code to simulate objects without bless?
- by user350571
I'm new to Perl and its blessing stuff to imitate class like functionality made me feel strange I even had to go to the bathroom.
Now, please tell me: what do you don't like, find wrong or strange with this code:
sub Person
{
my $age = shift || 15;
return
{
printAge => sub
{
print "Age -> $age\n";
},
changeAge => sub
{
$age = shift
}
}
}
my $p = Person();
my $p2 = Person(27);
$p->{printAge}->();
$p->{changeAge}->(30);
$p->{printAge}->();
$p2->{printAge}->();