So I would say that any code that *sets* $_ is, by definition, wrong.Unnecessary, perhaps, but not wrong. Setting $_ can be useful:
Instead of this:
You can write this:$h->{foo}{bar} =~ s/[._]/ /g; Some::Custom::Function($h->{foo}{bar}); $h->{foo}{bar} =~ s/^\s+//; $h->{foo}{bar} =~ s/\s+$//; $h->{foo}{bar} =~ s/`/'/g;
for ($h->{foo}{bar}) { s/[._]/ /g; Some::Custom::Function($_); s/^\s+//; s/\s+$//; s/`/'/g; };
map { $_ = foo( $bar, $_ ) } values %somehash;
In reply to Re^2: "$_" vs. $_
by mrpeabody
in thread "$_" vs. $_
by argv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |