Help for this page

Select Code to Download


  1. or download this
    package UsesClosures;
    
    ...
    sub get_attr    { &{ shift->{get_attr   } } };
    sub set_attr    { &{ shift->{set_attr   } } };
    sub some_method { &{ shift->{some_method} } };
    
  2. or download this
    my $o = UsesClosures->new();
    $o->set_attr(123);
    print $o->get_attr();
    $o->some_method();
    
  3. or download this
    package Dinner;
    
    ...
    
    sub wash_hands { &{ shift->{wash_hands} } };
    sub eat_food   { &{ shift->{eat_food  } } };
    
  4. or download this
    my $dirtyeater = Dinner->new();
    $dirtyeater->wash_hands();
    $dirtyeater->eat_food();