3 ms·
It's kind of obtuse. If you have to type out "$_", you might as well declare it and give it a good name. I personally have no issues doing: foreach @array
by sliverstorm 14y ago
It's kind of obtuse. If you have to type out "$_", you might as well declare it and give it a good name.
I personally have no issues doing:
foreach @array {
chomp;
print;
}
But as soon as I have to type "$_" I make a real variable.
- snaky 14y agoWhat's wrong to type $_ if you want to print "`$_'\n" in your example? Etc. I don't see any problem with that as $_ is clearly states that's a loop counter. And let's don't even talk about map/grep/sort and schwartzian transform.
- pfortuny 14y agoI don't think he sees that as a Problem. Only he thinks using it explicitly is not to his taste. I have a similar attitude: make it explicitly a new var if it is going to appear in the code. Your example is perfectly OK. TIMTOWTDI, really.
- singingfish 14y ago$_ is pronounced "it" and should only be used in small blocks of code. This is in much the same way that in a paragraph of text "it" should only be used for transitory sentences on the same topic as the previous one.