<?xml version="1.0" encoding="windows-1252"?>
<node id="303209" title="Re: Re: Re: Re: Think for yourself." created="2003-10-30 01:02:30" updated="2005-06-15 01:42:52">
<type id="11">
note</type>
<author id="278098">
gwadej</author>
<data>
<field name="doctext">
&lt;p&gt;I'm sorry. I appear to have added to the confusion, rather than clarifying. I should have begun by saying that I avoid using &lt;code&gt;map&lt;/code&gt; or &lt;code&gt;grep&lt;/code&gt; in &lt;code&gt;void&lt;/code&gt; context.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;An example of what I was trying to say is the code example below.&lt;/p&gt;

&lt;code&gt;
  my @minutes = map { $_ / 60 } @seconds;
&lt;/code&gt;

&lt;p&gt;In the &lt;code&gt;foreach&lt;/code&gt; style, this would be&lt;/p&gt;

&lt;code&gt;
  my @minutes = ();
  foreach my $sec (@seconds)
   {
    push @minutes, ($sec / 60);
   }
&lt;/code&gt;

&lt;p&gt;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 &lt;em&gt;read&lt;/em&gt; 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.&lt;/p&gt;

&lt;p&gt;Although this may seem like a simple example. I find many times that I can use these operators to reduce the &lt;em&gt;noise&lt;/em&gt; 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.&lt;/p&gt;

&lt;p&gt;Granted, if the code inside the block gets complicated enough, I may change to the &lt;code&gt;foreach&lt;/code&gt; style to emphasize the fact that this is not a &lt;em&gt;simple&lt;/em&gt; transformation.&lt;/p&gt;

&lt;p&gt;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.&amp;lt;grin type="embarassed"/&amp;gt;&lt;/p&gt;

&lt;div class="pmsig"&gt;&lt;div class="pmsig-278098"&gt;
G. Wade
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
296742</field>
<field name="parent_node">
296851</field>
</data>
</node>
