Perl classes like stuff
        Posted  
        
            by user350571
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user350571
        
        
        
        Published on 2010-05-26T06:07:01Z
        Indexed on 
            2010/05/26
            6:11 UTC
        
        
        Read the original article
        Hit count: 344
        
perl
|class-design
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.
© Stack Overflow or respective owner