Earlier quoted context omitted.
> variables, like $_. Which you don't use in real programs Oh really? What's wrong with $_ and since when it is?
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 l…
For example, the following code performs as expected, and prints "123"
use 5.016;
use warnings;
my @a = qw(1 2 3);
for (@a) {
my @b = qw(4 5 6);
for (@b) {
$_ = 1;
}
print;
}
This code works (prints "123") fine as well: use 5.016;
use warnings;
sub test {
my @b = qw(4 5 6);
for (@b) {
$_ = 1;
}
}
my @a = qw(1 2 3);
for (@a) {
test;
print;
}
The following causes a problem (prints "111"). Don't do this, it's stupid. use 5.016;
use warnings;
sub test {
$_ = 1;
}
my @a = qw(1 2 3);
for (@a) {
test;
print;
}
The moral? Buggy libraries are buggy, don't use them, or submit a fix.