|
|
|
|
|
by btilly
4787 days ago
|
|
The problem is that $_ is global and always in package main. A specific problem that fixed this in my memory was a bug in my co-worker's code which boiled down to his looping over an array with $_, then calling a function in his loop that was in a CPAN library that assigned to $_. The result was that he wiped out his whole array. Whenever you are calling out to code that someone else wrote, you don't know if issues like that could exist, and therefore it isn't safe to use $_. Conversely if you're writing code that someone else will call, be a good citizen and don't assign to $_ either implicitly or explicitly. |
|
For example, the following code performs as expected, and prints "123"
This code works (prints "123") fine as well: The following causes a problem (prints "111"). Don't do this, it's stupid. The moral? Buggy libraries are buggy, don't use them, or submit a fix.