The keyword my essentially restricts the scope of a variable to the block in which it is declared. It is much more complicated than that, but that, as I understand it, is the gist of it.
[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
Yes I think it is very good practices. If for no other reason than that if you use my and use strict; then you will never spend days searching for where you accidentally mispelled some variable name.
[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
The general rule of thumb is always to use 'my' unless you have a particular reason to use 'local' or 'our'.
nawlej - declaring a variable with 'my' *never* makes it global. If you happen to do so at the top of the script, then it will still be in scope anywhere in that package but won't be visible from any other package.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.