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


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.. :-)