Just why are lexicals "the right thing?"
Unless you are very careful to use local, package variables (the kind you get when you don't use my) are always global. Even when you do use local, there are many surprises waiting in store. Package variables make action at a distance far too easy.
Lexical variables, on the other hand, are usually very safe. You know that when you scope a lexical variable to a specific block, nothing outside of that block can access it. You also know that you are not clobbering any other variables of the same name from other scopes. It's just the right way to go 99.95% of the time. The whole history of computer science has proved this out -- people are constantly thinking of new ways to keep pieces of code from inadvertantly interacting with and breaking other pieces of code.
The second question is, what is the advantage of using this form of hash . . . vs. this form of hash
The first one you showed was a hash, the second was a hash reference. References are very useful for a variety of reasons, but unless you actually need one, I advise sticking with a plain hash. I have no objective reasons, other than reducing the amount of unnecessary syntax (which, especially when writing Perl code, is always something to strive for).
In reply to Re^3: when is "my" not necessary?
by revdiablo
in thread when is "my" not necessary?
by argv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |