Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: A question of style - declaring lexicals

by Ryszard (Priest)
on Jun 03, 2004 at 08:04 UTC ( #359975=note: print w/ replies, xml ) Need Help??


in reply to A question of style - declaring lexicals

I tend to declare my variables wrt to these guidelines.

  1. If the variable is used thru out an entire sub, I declare it at the top.
  2. If the variable is used exclusively within a loop, declare it inside the loop.
  3. If a variable will be used part way thru' the method/sub I will declare it on a line just before it is used.
I tend to keep away from globals unless i'm being particularly lazy, but in that case, the global is always declared at the top of the script.. :-)


Comment on Re: A question of style - declaring lexicals
Replies are listed 'Best First'.
Re: A question of style - declaring lexicals
by Abigail-II (Bishop) on Jun 03, 2004 at 13:38 UTC
    When do you consider a variable to be used "thru out an entire sub", and "used part way thru' the method/sub"? Is a variable that used for the first time on the second line used throughout, or part way?

    Abigail

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (20)
As of 2015-07-31 16:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls