The semantics and differences in variable capture mechanisms for closures between various programming languages is a fascinating topic. One of my favorite examples is^H^Hwas Ruby’s scoping mechanism for blocks. The problem is acknowledged and eloquently explained on page 105 in the second edition of the pickaxe book. I am particularly amused by the proposed pragmatic solution; keep your code small so that it is easy to spot any potential problem, and use some form of Hungarian notation to put local variables and block parameters in a different lexical namespace. Fortunately, this issue is fundamentally fixed in Ruby 1.9
Perl 5 got this right from the start.