in reply to Re^3: local variable syntax
in thread local variable syntax
Like all blanket statements, there are exceptions.
But these aren't even exceptions. They are simply other first-class cases.
Perhaps I should have said: Use my by default, use local when you understand why you can't use my in a specific situation.
That would certainly be better, but, like your previous post, it begs the usage context. Which is, namely: When you want to declare a variable. local is not good for declaring variables. In fact, it simply does not do that at all! What it does (and this was pretty much your first and only line of defence in Perl 4) is let you safely use a prior existing global variable in your "private" scope. As long as all scopes follow the protocol of localizing their variables before use, global variables can work fine. But that's a big "if", and lexical variables (introduced in Perl 5) allow a great measure of safety which doesn't even depend on every scope abiding by the rules.
|
|---|