It is important to understand the differences between my and local; just blindly only using my is little better than blindly only using local. Fundamentally, they're useful for different purposes, because they do different things. I like to think of my as a namespace qualifier that prevents collisions with anything outside the current block (or file). On the other hand, local has nothing whatsoever to do with namespaces but rather with time; I like to think of it as temporary assignment. It temporarily changes the value of a particular variable but allows it to revert back to its former value later.
The upshot of this is that you can use local to change *somebody else's* variable, temporarily. For instance, you can local a package-scoped variable from a module you're using, or a global special variable like $_ or $/ or whatnot. By doing this you can change the behavior of code that uses that variable -- not just your own code, but also any code that you call (e.g., by using local on $/ you can change the way the diamond operator (which is not, strictly speaking, your code) works when you call it, but allow its behavior to revert back to "normal" later when you're done). This is tremendously useful, but it's also completely different from anything you would do with my.
The only thing my and local have in common is that they both have to do with variable scope.
| [reply] |