in reply to Style Question on Closures

A closure is a code block with lexcially scoped variables. But only use them if you've got a good reason for that.

This is a simple example of what a closure is and how it works:

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
Only with dynamic information (like the $a's in this example), closures are useful.

2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$