Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: naming anonymous subroutines inner variables

by GrandFather (Saint)
on Jun 22, 2016 at 21:22 UTC ( #1166312=note: print w/replies, xml ) Need Help??

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
  • Comment on Re: naming anonymous subroutines inner variables

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1166312]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2022-11-29 00:12 GMT
Find Nodes?
    Voting Booth?