Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: naming anonymous subroutines inner variables

by GrandFather (Saint)
on Jun 22, 2016 at 21:22 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-25 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found