http://qs321.pair.com?node_id=1166312


in reply to naming anonymous subroutines inner variables

As a general thing don't use $_ where you can instead use a named variable. Names are vital pieces of documentation that help write correct code and facilitate maintenance by that future stranger who has to deal with your code.

In this case it would highlight the fact that the $_ content is being set during the for loop execution and maybe make you ponder what that implies for the content of the variable when the sub is actually called.

Even better, take the sub out of line. That fixes the immediate problem and also makes the business logic of the loop clearer, especially if you give the sub a sensible name.

Premature optimization is the root of all job security