The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 08-26-2005
vertigo23's Avatar
vertigo23 vertigo23 is offline
Registered User
  
 

Join Date: Jul 2005
Location: SF, CA
Posts: 73
From a purely practical point-of-view, it's not so much that globals are bad, as it is that locals are really handy. Say you're in a loop, and you want to do the same function with a different data in each iteration. If you use a local (my) variable to feed data to the function, you're guarenteed that no data from a previous iteration of the loop can pollute a later iteration, if say the variable doesn't get filled every time.

Also, with local variables, you can re-use common variable names like $i for loop iterations and not have to worry about there already being data in the var.