in reply to Object oriented Perl and Java: A brief examination of design.
Now, $val's scope extends to the two functions. Or you can make a function that manufactures an anonymous closure:{ my $val; sub set_value { $val = shift; } sub get_val { return $val; } }
sub create_func { my $val = shift; return { $val ++; return $val; } } my $increment_coderef = create_fund(1); my $value = $increment_coderef->(); #returns 2 my $value = $increment_coderef->(); #returns 3
|
|---|