Says Dave Mitchell: > Closures ... can also be dangerous and counter-intuitive, espcially to > the uninitiated. For example, how many people could say what the > following should output, with and without $x commented out, and why: > > { > my $x = "bar"; > sub foo { > # $x # <- uncommenting this line changes the outcome > return sub {$x}; > } > } > print foo()->(); > That is confusing, but it is not because closures are confusing. It is confusing because it is a BUG. In Perl 5, named subroutines are not properly closed. If the bug were fixed, the result would be 'bar' regardless of whether or not $x was commented. This would solve the problems with mod_perl also. The right way to fix this is not to eliminate closures, or to require declarations. The right way to fix this is to FIX THE BUG.Thread Previous | Thread Next