Perl classes like stuff
- by user350571
Hello, lovers of the camel.
I'm new to perl and it's 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}->();
I'm going to walk my dog, hope to get responses when I'm back. Thanks in advance. Cheers. Be back soon. Thanks again.