in reply to Style Question on Closures
Only with dynamic information (like the $a's in this example), closures are useful.sub closure { my $a = $_[0]; return sub { $a += 2 }; } my $first = closure(1); print $first->(), "\n"; # 3 print $first->(), "\n"; # 5 my $second = closure(14); print $second->(), "\n"; # 16 print $first->(), "\n"; # 7
|
---|