All of this talk (and disdain) for grep. Why?<br><br>And no one has mentioned it&#39;s counterpart: map<br><br>my @b_copy = map { 255 } @b;<br><br>I believe that is about as clear as it gets. No worries about scope. No use of modification of an array in place. I know that the ()x idiom does the same thing. Unfortunately, my mind pulls map and grep up more readily than the x operator and when it does, I usually have to test whether I have the context correct for what I&#39;m trying to do. map is very unambiguous: it always takes a list and always returns a list. (Now is when Yitzchak or Josh ben Jore will tell me how I&#39;m wrong....)
<br><br>Ivan<br><br>P.S. - I&#39;ve really enjoyed the last couple of active threads on this list. I like to see the discussions and see what various opinions are in the community. Thanks to everyone for sharing.<br><br><div>
<span class="gmail_quote">On 6/15/07, <b class="gmail_sendername">Bill Campbell</b> &lt;<a href="mailto:bill@celestial.com">bill@celestial.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Fri, Jun 15, 2007, John W. Krahn wrote:<br>&gt;Bill Campbell wrote:<br>&gt;&gt;<br>&gt;&gt; The author of the perl (Net::CIDR from CPAN) seems to like using grep as a<br>&gt;&gt; method of processing arrays while doing no regular expression checking.&nbsp;&nbsp;He
<br>&gt;&gt; also does things like this to create an array, @bcopy, the same size as @b,<br>&gt;&gt; populated with 255.&nbsp;&nbsp;This also takes advantage of perl&#39;s ``magic&#39;&#39; where<br>&gt;&gt; looping through an array allows one to modify elements of the array by
<br>&gt;&gt; manipulating $_;<br>&gt;&gt;<br>&gt;&gt; my @bcopy = @b;<br>&gt;&gt; grep { $_ = 255 } @bcopy;<br>&gt;<br>&gt;Or you could do that like this:<br>&gt;<br>&gt;$_ = 255 for my @bcopy = @b;<br><br>My biggest problem with this is that, without comments, many people
<br>wouldn&#39;t realize that ``$_ = 255&#39;&#39; in this loop context is modifying the<br>contents of the @bcopy array.&nbsp;&nbsp;I must admit that I&#39;ve used this ``feature&#39;&#39;<br>of perl many times, but I don&#39;t find it intuitively obvious.
<br><br>Would bcopy still exist outside of this statement?&nbsp;&nbsp;I would think that the<br>``my&#39;&#39; in the loop would be interpreted as local to the loop.<br><br>I tend to write code defensively, and break things into steps to be sure
<br>that the language is doing what I want, something like this:<br><br>my @bcopy = ();<br>for (@b) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push(@bcopy, 255);<br>}<br><br>There&#39;s no possible ambiguity with this.<br><br>Bill<br>--<br>INTERNET:&nbsp;&nbsp; 
<a href="mailto:bill@Celestial.COM">bill@Celestial.COM</a>&nbsp;&nbsp;Bill Campbell; Celestial Software LLC<br>URL: <a href="http://www.celestial.com/">http://www.celestial.com/</a>&nbsp;&nbsp;PO Box 820; 6641 E. Mercer Way<br>FAX:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(206) 232-9186&nbsp;&nbsp;Mercer Island, WA 98040-0820; (206) 236-1676
<br><br>``I have no reason to suppose that he, who would take away my Liberty, would<br>not when he had me in his Power, take away everything else.&#39;&#39;&nbsp;&nbsp;John Locke<br>_____________________________________________________________
<br>Seattle Perl Users Group Mailing List<br>&nbsp;&nbsp;&nbsp;&nbsp; POST TO: <a href="mailto:spug-list@pm.org">spug-list@pm.org</a><br>SUBSCRIPTION: <a href="http://mail.pm.org/mailman/listinfo/spug-list">http://mail.pm.org/mailman/listinfo/spug-list
</a><br>&nbsp;&nbsp;&nbsp;&nbsp;MEETINGS: 3rd Tuesdays<br>&nbsp;&nbsp;&nbsp;&nbsp;WEB PAGE: <a href="http://seattleperl.org/">http://seattleperl.org/</a><br></blockquote></div><br>