in reply to Re: A cleaner way of scoping variables
in thread A cleaner way of scoping variables

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

  • Comment on Re^2: A cleaner way of scoping variables