more useful options | |
PerlMonks |
Re: Newbie questionby hv (Prior) |
on Aug 23, 2022 at 16:19 UTC ( [id://11146327]=note: print w/replies, xml ) | Need Help?? |
As an example, I have used the absolute value function abs but I could have used abs($_). Which is best? Does it matter? Specifically on this point: others have pointed out that there is no difference functionally, so that leaves style and clarity to drive the choice. In my case, I hardly ever use the abs function (despite the fact that most of the code I write is maths-related). Because of that, I would choose always to write $abs = abs($_); rather than $abs = abs; - for the latter, I'd have to stop and think a few deciseconds longer any time I wrote it or read it. On the other hand, for functions that default to $_ that I use commonly, I'm much more likely to prefer the short form. On the gripping hand, I try to avoid over-reliance on $_. Normal for loops are almost always improved by naming the variable. I mostly have $_ in "right-to-left" code - maps, greps, modifier-for - and there, again, I look to name a variable if I'm going to be using it several times:
In Section
Seekers of Perl Wisdom
|
|