in reply to Re^2: local variable syntax
in thread local variable syntax
Well, I said "basically" never. Like all blanket statements, there are exceptions. Perhaps I should have said: Use my by default, use local when you understand why you can't use my in a specific situation. You can create 'stack-like' aggregates with local as you demonstrate, but you need a very good reason.
# some good reasons: # if you modify a side-effect global like $/, # do it in the smallest scope possible: my $slurped = do { local $/; <$some_Fhand> }; # override an element of a global aggregate in a # limited scope: { local $SIG{"ALRM"} = \&some_handler; alarm $timeout; some_action(); }
Of course, I agree that understanding the difference is much better than applying a blanket maxim. (Which is why I pointed to an article that does just that.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: local variable syntax
by jdporter (Paladin) on Apr 07, 2011 at 16:54 UTC |