But if you want to use the value a little farther below it probably means that you need that variable, and hence you should declare it, or maybe you should group together the parts of code that are working on the same temporary variable so that you can scope tightly.

just my 2 cents.

He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Another consideration along this lines and that of using subroutines is general code style/design.

If you break your code up more into subrotines, methods, modules, classes etc. you still have the problem though it is considerably less relevent.

i.e. if your whole code block (sub/method) is already naturally defined as 10-20 lines of code, then the fact $bar is scoped slightly longer than you want, hardly matters since it is going to go right out of scope a few lines later anyway when your subroutine/method ends.

I know my preference may vary from others, but when I get my code reduced to classes and a "driver" script that just says:

do_step_1
do_step_2
do_step_3
exit_gracefully

I am quite happy with it. Debugging generally very quickly gets you to 10-20 lines of code making it much easier to figure out. Then, if you are using global variables in this scenario, you deserve whatever you get...

When putting a smiley right before a closing parenthesis, do you:

Use two parentheses: (Like this: :) )
Use one parenthesis: (Like this: :)
Reverse direction of the smiley: (Like this: (: )
Use angle/square brackets instead of parentheses
Use C-style commenting to set the smiley off from the closing parenthesis
Make the smiley a dunce: (:>
I disapprove of emoticons
Other