|Welcome to the Monastery|
Re: Re: Re: Re: Think for yourself.by gwadej (Chaplain)
|on Oct 30, 2003 at 06:02 UTC||Need Help??|
I'm sorry. I appear to have added to the confusion, rather than clarifying. I should have begun by saying that I avoid using map or grep in void context.
What I was commenting on was your suggestion that the only reason for using those operators was that they are more concise and show a better grasp of Perl.
An example of what I was trying to say is the code example below.
In the foreach style, this would be
To me, the first signals the intent to transform a list of times in seconds into an equivalent list in minutes. The second has pretty much the same effect, but I have to read the code to see what the output is. In the first case, it seems obvious (to me, at least) that the output is the left side of the assignment.
Although this may seem like a simple example. I find many times that I can use these operators to reduce the noise characters in code like this. Sometimes that reduction is enough to make the overall code clearer by not spending space on relative minor pieces of logic.
Granted, if the code inside the block gets complicated enough, I may change to the foreach style to emphasize the fact that this is not a simple transformation.
I see this as a Perl idiom that can convey information to the maintainer when used carefully. I do agree that it can be horribly misused. (The less I say about that the better.<grin type="embarassed"/>