And the output would be exacly the same if you used my. Check the article mentioned above for an explanation on the difference. Doesnt make much sense thoug. The only real use for local as I see it is this:
- You have a subroutine which calls a few others, perhaps in someone else's code(a module perhaps).
- Now, you need to change a global variable( turn of warning for pre-5.6.0 perl or perhaps turn of buffered output).
- You dont want to remember to switch it back to what it was when you return from your routine. This is feasable if you do some error checking on all your calls, and want to return as soon as one of them fails somehow.
Solution: use local on the global variable, and set it to what you want. All the routines you call see the new value of this variable, and as soon as you return it is automagically reset to what it was.
If you had used my instead, only your routine would have seen the change. Any routine you called, would still have seen the old value, since my is lexically scoped.
GoldClaw