perl.fwp http://www.nntp.perl.org/group/perl.fwp/ ... Copyright 1998-2013 perl.org Thu, 23 May 2013 22:14:47 +0000 ask@perl.org FW: 3/15/2013 10:26:49 AM by Andrew Savige <br/>http://www.occamobile.com/zhvrm/htdza/hsp/gr/vo <br/><br/><br/><br/> 3/15/2013 10:26:49 AM .<br/><br/><br/>Andrew Savige<br/> http://www.nntp.perl.org/group/perl.fwp/2013/03/msg4214.html Fri, 15 Mar 2013 09:27:01 +0000 Re: seeking golfing advice by Smylers Aristotle Pagaltzis writes:<br/><br/>&gt; And if you have an array to work with in the first place, you can also<br/>&gt; <br/>&gt; @array[map 1+$_*2, 0..$#array/2]<br/>&gt; <br/>&gt; which is 3 characters longer than the grep version<br/><br/>I think that actually gives you the even elements. For the odd elements<br/>(which are even array indices, in Perl&#39;s terms) you don&#39;t need the C&lt;<br/>1+&gt; in there, saving 3 characters.<br/><br/> @array[map$_*2,0..$#array/2]<br/><br/>The shortest variant like that I&#39;ve found for even characters is:<br/><br/> @array[map$_*2-1,1..@array/2]<br/><br/>@array is one character shorter than $#array, but to avoid getting an<br/>unwanted undef element when @array has an even number of elements in it<br/>you need to start at 1 rather than 0, which makes the subtraction<br/>necessary.<br/><br/>Smylers<br/>-- <br/>http://twitter.com/Smylers2<br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4213.html Sat, 19 May 2012 03:19:25 +0000 Re: seeking golfing advice by John Douglas Porter <br/><br/>&gt; From: Aristotle Pagaltzis &lt;pagaltzis@gmx.de&gt;<br/>&gt; Subject: Re: seeking golfing advice<br/>&gt; To: fwp@perl.org<br/>&gt; Date: Friday, May 18, 2012, 5:29 AM<br/>&gt; * Steve Fink &lt;sphink@gmail.com&gt;<br/>&gt; [2012-05-18 10:25]:<br/>&gt; &gt; On Thu, May 17, 2012 at 3:14 AM, Aristotle Pagaltzis<br/>&gt; &lt;pagaltzis@gmx.de&gt;<br/>&gt; wrote:<br/>&gt; &gt; &gt; * Mike Erickson &lt;mee@quidquam.com&gt;<br/>&gt; [2012-05-16 15:45]:<br/>&gt; &gt; &gt; &gt; If you don&#39;t care about order, but just want<br/>&gt; those elements, you<br/>&gt; &gt; &gt; &gt; can also do:<br/>&gt; &gt; &gt; &gt;<br/>&gt; &gt; &gt; &gt; keys%{{@a}}<br/>&gt; &gt; &gt;<br/>&gt; &gt; &gt; There is more than order that gets lost. If you<br/>&gt; use `keys` you also<br/>&gt; &gt; &gt; get everything back stringified &ndash; undefs are<br/>&gt; lost and references<br/>&gt; &gt; &gt; break. If you use `values` these problems go<br/>&gt; away&hellip; except that to<br/>&gt; &gt; &gt; get the odd-index elements from it you have to<br/>&gt; `reverse` the array,<br/>&gt; &gt; &gt; at which point a not-especially-golfed grep is<br/>&gt; shorter.<br/>&gt; &gt;<br/>&gt; &gt; So you&#39;d want<br/>&gt; &gt;<br/>&gt; &gt;&nbsp; values%{{1,@a}}<br/>&gt; &gt;<br/>&gt; &gt; then<br/>&gt; <br/>&gt; D&rsquo;oh!<br/><br/><br/>D::oh is right. You get an unwanted extra undef at the end of such list.<br/><br/><br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4212.html Fri, 18 May 2012 06:17:56 +0000 Re: seeking golfing advice by Aristotle Pagaltzis * Steve Fink &lt;sphink@gmail.com&gt; [2012-05-18 10:25]:<br/>&gt; On Thu, May 17, 2012 at 3:14 AM, Aristotle Pagaltzis &lt;pagaltzis@gmx.de&gt; wrote:<br/>&gt; &gt; * Mike Erickson &lt;mee@quidquam.com&gt; [2012-05-16 15:45]:<br/>&gt; &gt; &gt; If you don&#39;t care about order, but just want those elements, you<br/>&gt; &gt; &gt; can also do:<br/>&gt; &gt; &gt;<br/>&gt; &gt; &gt; keys%{{@a}}<br/>&gt; &gt;<br/>&gt; &gt; There is more than order that gets lost. If you use `keys` you also<br/>&gt; &gt; get everything back stringified &ndash; undefs are lost and references<br/>&gt; &gt; break. If you use `values` these problems go away&hellip; except that to<br/>&gt; &gt; get the odd-index elements from it you have to `reverse` the array,<br/>&gt; &gt; at which point a not-especially-golfed grep is shorter.<br/>&gt;<br/>&gt; So you&#39;d want<br/>&gt;<br/>&gt; values%{{1,@a}}<br/>&gt;<br/>&gt; then<br/><br/>D&rsquo;oh!<br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4211.html Fri, 18 May 2012 02:29:29 +0000 Re: seeking golfing advice by Steve Fink On Thu, May 17, 2012 at 3:14 AM, Aristotle Pagaltzis &lt;pagaltzis@gmx.de&gt; wrote:<br/>&gt; * Mike Erickson &lt;mee@quidquam.com&gt; [2012-05-16 15:45]:<br/>&gt;&gt; If you don&#39;t care about order, but just want those elements, you can<br/>&gt;&gt; also do:<br/>&gt;&gt;<br/>&gt;&gt; keys%{{@a}}<br/>&gt;<br/>&gt; There is more than order that gets lost. If you use `keys` you also get<br/>&gt; everything back stringified &ndash; undefs are lost and references break. If<br/>&gt; you use `values` these problems go away&hellip; except that to get the odd-<br/>&gt; index elements from it you have to `reverse` the array, at which point<br/>&gt; a not-especially-golfed grep is shorter.<br/><br/>So you&#39;d want<br/><br/> values%{{1,@a}}<br/><br/>then<br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4210.html Fri, 18 May 2012 01:24:18 +0000 Re: seeking golfing advice by Aristotle Pagaltzis * Pau Amma &lt;pauamma@gundo.com&gt; [2012-05-16 14:55]:<br/>&gt; If, as it sounds, you want to balance golfiness and strictness, you<br/>&gt; could also say:<br/>&gt;<br/>&gt; @array[grep $_%2, keys @array]<br/>&gt;<br/>&gt; (or @array[grep $_%2^1, keys @array] if you set $[ to 1 - but you<br/>&gt; didn&#39;t do that, right? :-) )<br/><br/>Btw, `keys@foo` and `0..$#foo` are equally long&hellip; but the latter works<br/>with old perls (advantage production) *and* looks more line-noisy<br/>(advantage golf).<br/><br/>And if you have an array to work with in the first place, you can also<br/><br/> @array[map 1+$_*2, 0..$#array/2]<br/><br/>which is 3 characters longer than the grep version in exchange for doing<br/>half as much work. (For even elements, the map and grep solutions would<br/>yield exactly equally long code, with half-as-much-work still applying.)<br/><br/>-- <br/>*AUTOLOAD=*_;sub _{s/$/$&quot;/;s/(.*):://;wantarray//substr$_,-1,1,&quot;,$/&quot;;print;$1}<br/>&amp;Just-&gt;another-&gt;Perl-&gt;hack;<br/>#Aristotle Pagaltzis // &lt;http://plasmasturm.org/&gt;<br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4209.html Thu, 17 May 2012 03:28:29 +0000 Re: seeking golfing advice by Aristotle Pagaltzis * Mike Erickson &lt;mee@quidquam.com&gt; [2012-05-16 15:45]:<br/>&gt; If you don&#39;t care about order, but just want those elements, you can<br/>&gt; also do:<br/>&gt;<br/>&gt; keys%{{@a}}<br/><br/>There is more than order that gets lost. If you use `keys` you also get<br/>everything back stringified &ndash; undefs are lost and references break. If<br/>you use `values` these problems go away&hellip; except that to get the odd-<br/>index elements from it you have to `reverse` the array, at which point<br/>a not-especially-golfed grep is shorter.<br/><br/>-- <br/>*AUTOLOAD=*_;sub _{s/$/$&quot;/;s/(.*):://;wantarray//substr$_,-1,1,&quot;,$/&quot;;print;$1}<br/>&amp;Just-&gt;another-&gt;Perl-&gt;hack;<br/>#Aristotle Pagaltzis // &lt;http://plasmasturm.org/&gt;<br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4208.html Thu, 17 May 2012 03:15:10 +0000 Re: seeking golfing advice by Ronald J Kimball On Wed, May 16, 2012 at 04:40:40AM -0700, John Douglas Porter wrote:<br/>&gt; And of course, use grep, as others have said.<br/>&gt; <br/>&gt; @list[ grep !$_%2, 0..$#list ];<br/>&gt; <br/>&gt; that gets you every other element, beginning with the first.<br/><br/>! has higher precedence than %, so this actually gets you just the<br/>first element.<br/><br/><br/>You need to add parentheses to get the correct result:<br/><br/>@list[grep!($_%2),0..$#list];<br/><br/><br/>There are a couple ways to shave a character from that:<br/><br/>@list[grep$_%2-1,0..$#list];<br/>@list[grep$_+1&amp;1,0..$#list];<br/><br/>Ronald<br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4207.html Wed, 16 May 2012 08:22:42 +0000 AW: seeking golfing advice by Moritz, Georg &gt; btw here is an example :<br/>&gt; <br/>&gt; the code, applied on (1, 2, 3, 4) would return (1, 3). Thanks<br/><br/>so you want to check every element for oddity of its value, not its index, right?<br/><br/>@list = grep{$_%2}@array;<br/><br/>cheers,<br/>0--gg-<br/><br/>&gt; On 16 May 2012 13:15, damien krotkine &lt;dkrotkine@gmail.com&gt; wrote:<br/>&gt; &gt; Hi,<br/>&gt; &gt;<br/>&gt; &gt; I&#39;m using this code to get a list of only the odd elements of an<br/>&gt; &gt; array. The resulting list must have the same order as the array.<br/>&gt; &gt;<br/>&gt; &gt; map { state $f; ($_) x (++$f%2) } &nbsp;@array;<br/>&gt; &gt;<br/>&gt; &gt; I&#39;m looking for advice to make it shorter or nicer. Everything in perl<br/>&gt; &gt; 5.12 is allowed, but must pass use strict. I&#39;ve failed at using the<br/>&gt; &gt; &#39;..&#39; operator to act as a flip/flop operator...<br/>&gt; &gt;<br/>&gt; &gt; thanks,<br/>&gt; &gt; dams<br/>&gt;<br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4206.html Wed, 16 May 2012 07:48:22 +0000 Re: seeking golfing advice by Mike Erickson On 05/16/2012 07:46 AM, damien krotkine wrote:<br/>&gt; Hi all,<br/>&gt;<br/>&gt; thanks for the quick answers :)<br/>&gt;<br/>&gt; first of all, despite my attempt to clear things up with an example, I<br/>&gt; failed :) What I wante is &quot;every other element, beginning with the<br/>&gt; first&quot;, so :<br/>&gt;<br/>&gt; ( &#39;foo&#39;, 3, 42, &#39;bar) should become ( &#39;foo&#39;, 42).<br/><br/>If you don&#39;t care about order, but just want those elements, you can <br/>also do:<br/><br/>keys%{{@a}}<br/><br/>{@a} being a hash ref constructed from @a<br/>%{ } dereferencing that hash ref<br/>keys pulling out the keys, ie. the odd elements of the orig. list<br/><br/>hth,<br/><br/>Mike<br/><br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4205.html Wed, 16 May 2012 06:41:42 +0000 Re: seeking golfing advice by Pau Amma On Wed, May 16, 2012 12:25 pm, damien krotkine wrote:<br/>&gt; On 16 May 2012 14:02, Peter Makholm &lt;peter@makholm.net&gt; wrote:<br/>&gt; [ ... ]<br/>&gt;<br/>&gt;&gt; So basically you are trading 8 characters for readability and probably<br/>&gt;&gt; speed. Why do you want that?<br/>&gt;<br/>&gt; For fun, purely. I&#39;ll stick with $f % 2 for now, it seems a right<br/>&gt; balance compared to the code lying around.<br/><br/>If, as it sounds, you want to balance golfiness and strictness, you could<br/>also say:<br/><br/>@array[grep $_%2, keys @array]<br/><br/>(or @array[grep $_%2^1, keys @array] if you set $[ to 1 - but you didn&#39;t<br/>do that, right? :-) )<br/><br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4204.html Wed, 16 May 2012 05:52:17 +0000 Re: seeking golfing advice by damien krotkine On 16 May 2012 14:02, Peter Makholm &lt;peter@makholm.net&gt; wrote:<br/>&gt; damien krotkine &lt;dkrotkine@gmail.com&gt; writes:<br/>&gt;<br/>&gt;&gt; Indeed grep is much better. As the code is used in a more complex<br/>&gt;&gt; structured I got lost and confused and ended up using map, blah.<br/>&gt;&gt;<br/>&gt;&gt; $|-- was what I was looking for :)<br/>&gt;<br/>&gt; No, reading my posts again it I see that it clearly doesn&#39;t do what you<br/>&gt; ask for. You are actually looking for --$|.<br/><br/>Oops yes, --$| indeed, sorry.<br/><br/>[ ... ]<br/><br/>&gt; So basically you are trading 8 characters for readability and probably<br/>&gt; speed. Why do you want that?<br/><br/>For fun, purely. I&#39;ll stick with $f % 2 for now, it seems a right<br/>balance compared to the code lying around.<br/><br/>dams<br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4203.html Wed, 16 May 2012 05:25:36 +0000 Re: seeking golfing advice by Peter Makholm damien krotkine &lt;dkrotkine@gmail.com&gt; writes:<br/><br/>&gt; Indeed grep is much better. As the code is used in a more complex<br/>&gt; structured I got lost and confused and ended up using map, blah.<br/>&gt;<br/>&gt; $|-- was what I was looking for :)<br/><br/>No, reading my posts again it I see that it clearly doesn&#39;t do what you<br/>ask for. You are actually looking for --$|.<br/><br/>&gt; Finally, one question : why is $|-- not recommended in production, if<br/>&gt; the following conditions are met : I&#39;m not running in threads, not in<br/>&gt; an event-loop that might be affected by $| being set, and I&#39;ll take<br/>&gt; care of resetting $| appropriately at the end.<br/><br/>It depends on an obscure, undocumented feature of a magic variable, which<br/>unless used correct may have an unintended action at a distance. This<br/>makes the code hard to maintain for the next developer (which might be<br/>youself 14 days down the road).<br/><br/>What do you think you are optimizing for?<br/><br/>I would guess that the $| is also a bit slower, as it needs to at least<br/>test if the filehandle needs to be flushed even though you know that no<br/>one had the chance to write to it.<br/><br/>So basically you are trading 8 characters for readability and probably<br/>speed. Why do you want that?<br/><br/>//Makholm<br/><br/><br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4202.html Wed, 16 May 2012 05:03:14 +0000 Re: seeking golfing advice by damien krotkine Hi all,<br/><br/>thanks for the quick answers :)<br/><br/>first of all, despite my attempt to clear things up with an example, I<br/>failed :) What I wante is &quot;every other element, beginning with the<br/>first&quot;, so :<br/><br/>( &#39;foo&#39;, 3, 42, &#39;bar) should become ( &#39;foo&#39;, 42).<br/><br/>Indeed grep is much better. As the code is used in a more complex<br/>structured I got lost and confused and ended up using map, blah.<br/><br/>$|-- was what I was looking for :)<br/><br/>About golfing and strictness I am well aware that the two are<br/>incompatible. What I originally meant is to get something with a sane<br/>balance between the two.<br/><br/>Finally, one question : why is $|-- not recommended in production, if<br/>the following conditions are met : I&#39;m not running in threads, not in<br/>an event-loop that might be affected by $| being set, and I&#39;ll take<br/>care of resetting $| appropriately at the end.<br/><br/>Even in this case, wouldn&#39;t you recommend using $| ?<br/><br/><br/>Thanks again<br/><br/>On 16 May 2012 13:36, Peter Makholm &lt;peter@makholm.net&gt; wrote:<br/>&gt; Peter Makholm &lt;peter@makholm.net&gt; writes:<br/>&gt;<br/>&gt;&gt; damien krotkine &lt;dkrotkine@gmail.com&gt; writes:<br/>&gt;&gt;<br/>&gt;&gt;&gt; I&#39;m using this code to get a list of only the odd elements of an<br/>&gt;&gt;&gt; array. The resulting list must have the same order as the array.<br/>&gt;&gt;&gt;<br/>&gt;&gt;&gt; map { state $f; ($_) x (++$f%2) } &nbsp;@array;<br/>&gt;<br/>&gt; Wow, you asked for golfing advice in the subject and a nice solution in<br/>&gt; the actual text. Those requirements are quite often very incompatible.<br/>&gt;<br/>&gt;&gt; If you want only to get some elements of a list is is much more obvious<br/>&gt;&gt; to use grep instead of map:<br/>&gt;&gt;<br/>&gt;&gt; &nbsp; grep { ++$f%2 } @array<br/>&gt;<br/>&gt; This is probably as nice as it gets. For strictness I would just declare<br/>&gt; $f as a lexical variable just outside the grep. But asking for golfing<br/>&gt; advice is not compliant with strictness or niceness.<br/>&gt;<br/>&gt;&gt; And remove unneeded syntax<br/>&gt;&gt;<br/>&gt;&gt; &nbsp; grep$|--,@array<br/>&gt;<br/>&gt; I think this would be the golfing solution, but as with everything alse<br/>&gt; related to perl golfing don&#39;t use it in production code.<br/>&gt;<br/>&gt; //Makholm<br/>&gt;<br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4201.html Wed, 16 May 2012 04:46:43 +0000 Re: seeking golfing advice by John Douglas Porter And of course, use grep, as others have said.<br/><br/>@list[ grep !$_%2, 0..$#list ];<br/><br/>that gets you every other element, beginning with the first.<br/><br/><br/>--- On Wed, 5/16/12, John Douglas Porter &lt;johndporter@yahoo.com&gt; wrote:<br/><br/>&gt; From: John Douglas Porter &lt;johndporter@yahoo.com&gt;<br/>&gt; Subject: Re: seeking golfing advice<br/>&gt; To: fwp@perl.org<br/>&gt; Date: Wednesday, May 16, 2012, 7:35 AM<br/>&gt; It&#39;s not clear whether you want<br/>&gt; &quot;every other element, beginning with the first&quot; or &quot;every<br/>&gt; numeric element with the property &#39;odd&#39;&quot;.&nbsp; Your example<br/>&gt; doesn&#39;t clear that up at all. :-)<br/>&gt; <br/>&gt; If it&#39;s the latter you want:<br/>&gt; <br/>&gt; map { $_ &amp; 1 ? $_ : () } @l;<br/>&gt; <br/>&gt; <br/>&gt; --- On Wed, 5/16/12, damien krotkine &lt;dkrotkine@gmail.com&gt;<br/>&gt; wrote:<br/>&gt; <br/>&gt; &gt; From: damien krotkine &lt;dkrotkine@gmail.com&gt;<br/>&gt; &gt; Subject: Re: seeking golfing advice<br/>&gt; &gt; To: fwp@perl.org<br/>&gt; &gt; Date: Wednesday, May 16, 2012, 7:19 AM<br/>&gt; &gt; btw here is an example :<br/>&gt; &gt; <br/>&gt; &gt; the code, applied on (1, 2, 3, 4) would return (1, 3).<br/>&gt; &gt; Thanks<br/>&gt; &gt; <br/>&gt; &gt; On 16 May 2012 13:15, damien krotkine &lt;dkrotkine@gmail.com&gt;<br/>&gt; &gt; wrote:<br/>&gt; &gt; &gt; Hi,<br/>&gt; &gt; &gt;<br/>&gt; &gt; &gt; I&#39;m using this code to get a list of only the odd<br/>&gt; &gt; elements of an<br/>&gt; &gt; &gt; array. The resulting list must have the same order<br/>&gt; as<br/>&gt; &gt; the array.<br/>&gt; &gt; &gt;<br/>&gt; &gt; &gt; map { state $f; ($_) x (++$f%2) } &nbsp;@array;<br/>&gt; &gt; &gt;<br/>&gt; &gt; &gt; I&#39;m looking for advice to make it shorter or<br/>&gt; nicer.<br/>&gt; &gt; Everything in perl<br/>&gt; &gt; &gt; 5.12 is allowed, but must pass use strict. I&#39;ve<br/>&gt; failed<br/>&gt; &gt; at using the<br/>&gt; &gt; &gt; &#39;..&#39; operator to act as a flip/flop operator...<br/>&gt; &gt; &gt;<br/>&gt; &gt; &gt; thanks,<br/>&gt; &gt; &gt; dams<br/>&gt; &gt;<br/>&gt;<br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4200.html Wed, 16 May 2012 04:40:51 +0000 Re: seeking golfing advice by Peter Makholm Peter Makholm &lt;peter@makholm.net&gt; writes:<br/><br/>&gt; damien krotkine &lt;dkrotkine@gmail.com&gt; writes:<br/>&gt;<br/>&gt;&gt; I&#39;m using this code to get a list of only the odd elements of an<br/>&gt;&gt; array. The resulting list must have the same order as the array.<br/>&gt;&gt;<br/>&gt;&gt; map { state $f; ($_) x (++$f%2) } @array;<br/><br/>Wow, you asked for golfing advice in the subject and a nice solution in<br/>the actual text. Those requirements are quite often very incompatible.<br/><br/>&gt; If you want only to get some elements of a list is is much more obvious<br/>&gt; to use grep instead of map:<br/>&gt;<br/>&gt; grep { ++$f%2 } @array<br/><br/>This is probably as nice as it gets. For strictness I would just declare<br/>$f as a lexical variable just outside the grep. But asking for golfing<br/>advice is not compliant with strictness or niceness.<br/><br/>&gt; And remove unneeded syntax<br/>&gt;<br/>&gt; grep$|--,@array<br/><br/>I think this would be the golfing solution, but as with everything alse<br/>related to perl golfing don&#39;t use it in production code.<br/><br/>//Makholm<br/><br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4199.html Wed, 16 May 2012 04:36:52 +0000 Re: seeking golfing advice by John Douglas Porter It&#39;s not clear whether you want &quot;every other element, beginning with the first&quot; or &quot;every numeric element with the property &#39;odd&#39;&quot;. Your example doesn&#39;t clear that up at all. :-)<br/><br/>If it&#39;s the latter you want:<br/><br/>map { $_ &amp; 1 ? $_ : () } @l;<br/><br/><br/>--- On Wed, 5/16/12, damien krotkine &lt;dkrotkine@gmail.com&gt; wrote:<br/><br/>&gt; From: damien krotkine &lt;dkrotkine@gmail.com&gt;<br/>&gt; Subject: Re: seeking golfing advice<br/>&gt; To: fwp@perl.org<br/>&gt; Date: Wednesday, May 16, 2012, 7:19 AM<br/>&gt; btw here is an example :<br/>&gt; <br/>&gt; the code, applied on (1, 2, 3, 4) would return (1, 3).<br/>&gt; Thanks<br/>&gt; <br/>&gt; On 16 May 2012 13:15, damien krotkine &lt;dkrotkine@gmail.com&gt;<br/>&gt; wrote:<br/>&gt; &gt; Hi,<br/>&gt; &gt;<br/>&gt; &gt; I&#39;m using this code to get a list of only the odd<br/>&gt; elements of an<br/>&gt; &gt; array. The resulting list must have the same order as<br/>&gt; the array.<br/>&gt; &gt;<br/>&gt; &gt; map { state $f; ($_) x (++$f%2) } &nbsp;@array;<br/>&gt; &gt;<br/>&gt; &gt; I&#39;m looking for advice to make it shorter or nicer.<br/>&gt; Everything in perl<br/>&gt; &gt; 5.12 is allowed, but must pass use strict. I&#39;ve failed<br/>&gt; at using the<br/>&gt; &gt; &#39;..&#39; operator to act as a flip/flop operator...<br/>&gt; &gt;<br/>&gt; &gt; thanks,<br/>&gt; &gt; dams<br/>&gt;<br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4198.html Wed, 16 May 2012 04:35:48 +0000 Re: seeking golfing advice by Peter Makholm damien krotkine &lt;dkrotkine@gmail.com&gt; writes:<br/><br/>&gt; I&#39;m using this code to get a list of only the odd elements of an<br/>&gt; array. The resulting list must have the same order as the array.<br/>&gt;<br/>&gt; map { state $f; ($_) x (++$f%2) } @array;<br/><br/>If you want only to get some elements of a list is is much more obvious<br/>to use grep instead of map:<br/><br/> grep { ++$f%2 } @array<br/><br/>Then use the magical flip-flop variable:<br/> <br/> grep { $|-- } @array<br/><br/>And remove unneeded syntax<br/><br/> grep$|--,@array<br/><br/>//Makholm<br/><br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4197.html Wed, 16 May 2012 04:31:26 +0000 Re: seeking golfing advice by Daniel Cutter On 16.05.2012 13:19, damien krotkine wrote:<br/>&gt; btw here is an example :<br/>&gt;<br/>&gt; the code, applied on (1, 2, 3, 4) would return (1, 3). Thanks<br/>&gt;<br/>&gt; On 16 May 2012 13:15, damien krotkine&lt;dkrotkine@gmail.com&gt; wrote:<br/>&gt;&gt; Hi,<br/>&gt;&gt;<br/>&gt;&gt; I&#39;m using this code to get a list of only the odd elements of an<br/>&gt;&gt; array. The resulting list must have the same order as the array.<br/>&gt;&gt;<br/>&gt;&gt; map { state $f; ($_) x (++$f%2) } @array;<br/>&gt;&gt;<br/>&gt;&gt; I&#39;m looking for advice to make it shorter or nicer. Everything in perl<br/>&gt;&gt; 5.12 is allowed, but must pass use strict. I&#39;ve failed at using the<br/>&gt;&gt; &#39;..&#39; operator to act as a flip/flop operator...<br/>&gt;&gt;<br/>&gt;&gt; thanks,<br/>&gt;&gt; dams<br/><br/>Isn&#39;t this what grep is for?<br/><br/> 1 #!perl<br/> 2 use strict;<br/> 3 my @array=(1,2,3,4);<br/> 4 my $f;<br/> 5 my @result = grep {++$f%2} @array;<br/> 6 print &quot;@result\n&quot;;<br/><br/>-- <br/>*Daniel Cutter*<br/><br/>s/\b[^a]/\u$&amp;/g,s;$;,;,print for join$,,map{(&#39;acehjklnoprstu&#39;<br/>=~m(.)g,$&quot;)[/\d/?$_:hex]}q(4dbce078c32ae92a6e30152aff)=~m(.)g<br/><br/><br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4196.html Wed, 16 May 2012 04:29:36 +0000 Re: seeking golfing advice by damien krotkine btw here is an example :<br/><br/>the code, applied on (1, 2, 3, 4) would return (1, 3). Thanks<br/><br/>On 16 May 2012 13:15, damien krotkine &lt;dkrotkine@gmail.com&gt; wrote:<br/>&gt; Hi,<br/>&gt;<br/>&gt; I&#39;m using this code to get a list of only the odd elements of an<br/>&gt; array. The resulting list must have the same order as the array.<br/>&gt;<br/>&gt; map { state $f; ($_) x (++$f%2) } &nbsp;@array;<br/>&gt;<br/>&gt; I&#39;m looking for advice to make it shorter or nicer. Everything in perl<br/>&gt; 5.12 is allowed, but must pass use strict. I&#39;ve failed at using the<br/>&gt; &#39;..&#39; operator to act as a flip/flop operator...<br/>&gt;<br/>&gt; thanks,<br/>&gt; dams<br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4195.html Wed, 16 May 2012 04:19:09 +0000 seeking golfing advice by damien krotkine Hi,<br/><br/>I&#39;m using this code to get a list of only the odd elements of an<br/>array. The resulting list must have the same order as the array.<br/><br/>map { state $f; ($_) x (++$f%2) } @array;<br/><br/>I&#39;m looking for advice to make it shorter or nicer. Everything in perl<br/>5.12 is allowed, but must pass use strict. I&#39;ve failed at using the<br/>&#39;..&#39; operator to act as a flip/flop operator...<br/><br/>thanks,<br/>dams<br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4194.html Wed, 16 May 2012 04:16:01 +0000 The History of Acme::Bleach and Acme::EyeDrops by Andrew Savige The story behind Acme::Bleach and its many cousins:<br/><br/>&nbsp;http://www.perlmonks.org/?node_id=967004<br/><br/>Feedback and anecdotes welcome.<br/><br/>Thanks,<br/>/-\<br/> http://www.nntp.perl.org/group/perl.fwp/2012/05/msg4193.html Wed, 02 May 2012 05:56:32 +0000 Re: Secret operators: the documentation by Michael R . Wolf On Mar 16, 2012, at 4:44 AM, Philippe Bruhat (BooK) wrote:<br/><br/>&gt; A few years back, I started to write a manual page about Perl secret operators,<br/>&gt; with the goal of getting it into the official Perl documentation at some point.<br/><br/><br/><br/>A few comments&hellip;<br/><br/>1. It would be nice to do a bit of documentation on *why* or *how* some of these work. Perhaps a Deparse would be sufficient (as in Eskimo greeting), but English is also a good tool.<br/><br/>For starters, I didn&#39;t figure out how &quot;Ornate double-bladed sword worked&quot;. I&#39;m sure I could have created the trail alone, but it would be nice to follow someone else&#39;s blaze.<br/><br/>2. Given how dangerous this one could be (to a psyche) if researched deeply (years of therapy&hellip;)<br/><br/> =( )= Goatse scalar / list context<br/> <br/>I&#39;d suggest another name -- Saturn. Yes, snicker if you will. Saturn *is* the son of the Greek deity Uranus, but that&#39;s only a 2nd order, inside joke. The operator looks like Saturn, even when spaces are inserted (as will be likely with syntax formatting editors or perltidy(1))! <br/><br/>=( )= Saturn scalar / list context<br/>= ( ) = Saturn scalar / list context<br/><br/>Keep the old name if you wish, but add one that&#39;s more psychologically healthy, too!!! (P.S. Thanks for the warning. That&#39;s just plain *responsible* behavior to the community!!! One image could ruin someone&#39;s whole view of Perl.)<br/><br/>Michael<br/><br/>-- <br/>Michael R. Wolf<br/> All mammals learn by playing!<br/> MichaelRWolf@att.net<br/><br/><br/><br/> http://www.nntp.perl.org/group/perl.fwp/2012/04/msg4192.html Fri, 06 Apr 2012 18:26:31 +0000 Re: Secret operators: the documentation by John Douglas Porter <br/>Philippe Bruhat (BooK) &lt;philippe.bruhat@free.fr&gt; wrote:<br/>&gt; Andrew Savige wrote:<br/>&gt; &gt; <br/>&gt; &gt; I wonder if --$| and $|--, ... described<br/>&gt; &gt; by japhy as &quot;the magical flip flop variable&quot;<br/>&gt; &gt; qualifies as a secret operator?<br/>&gt; <br/>&gt; My rule has been to keep<br/>&gt; only the well-known operators, or the ones that had a<br/>&gt; nickname that<br/>&gt; corresponded to their looks, not their function.<br/>&gt; <br/>&gt; Under that rulle, the magical flip-flop wouldn&#39;t have fit.<br/><br/>Not to mention the fact that it&#39;s not an operator. :-)<br/><br/>-- <br/>john &quot;many jars&quot; porter<br/><br/> http://www.nntp.perl.org/group/perl.fwp/2012/04/msg4191.html Tue, 03 Apr 2012 04:55:20 +0000 Re: Secret operators: the documentation by Philippe Bruhat On Tue, Apr 03, 2012 at 03:43:54AM -0700, Andrew Savige wrote:<br/>&gt; <br/>&gt; <br/>&gt; I wonder if --$| and $|--, very popular in golf, and described<br/>&gt; by japhy as &quot;the magical flip flop variable&quot; at:<br/>&gt; <br/>&gt; &nbsp;http://www.nntp.perl.org/group/perl.fwp/2002/01/msg1367.html<br/>&gt; <br/>&gt; qualifies as a secret operator?<br/>&gt; <br/><br/>I have had several requests for adding more obscure constructs (see<br/>https://github.com/book/perlsecret/issues). My rule has been to keep<br/>only the well-known operators, or the ones that had a nickname that<br/>corresponded to their looks, not their function.<br/><br/>Under that rulle, the magical flip-flop wouldn&#39;t have fit.<br/><br/>Anyway, I guess others can decide what gets in when the branch merged<br/>into blead.<br/><br/>-- <br/> Philippe Bruhat (BooK)<br/><br/> Out of the worst can often come the best.<br/> (Moral from Groo The Wanderer #57 (Epic))<br/> http://www.nntp.perl.org/group/perl.fwp/2012/04/msg4190.html Tue, 03 Apr 2012 04:35:05 +0000 Re: Secret operators: the documentation by Philippe Bruhat On Mon, Apr 02, 2012 at 06:28:56PM +0200, Alexis Sukrieh wrote:<br/>&gt; Le 16 mars 2012 12:44, Philippe Bruhat (BooK)<br/>&gt; &lt;philippe.bruhat@free.fr&gt; a &eacute;crit :<br/>&gt; &gt; So,<br/>&gt; &gt;<br/>&gt; &gt; A few years back, I started to write a manual page about Perl secret operators,<br/>&gt; &gt; with the goal of getting it into the official Perl documentation at some point.<br/>&gt; [...]<br/>&gt; &gt; Patches welcome.<br/>&gt; &gt;<br/>&gt; &gt; When it&#39;s stabilized enough, I&#39;ll send a patch to p5p.<br/>&gt; <br/>&gt; Nice work :)<br/>&gt; <br/>&gt; I have a question though;<br/>&gt; <br/>&gt; Did you change your mind about the &quot;A word of warning&quot; section? It<br/>&gt; sounds that it won&#39;t fit well in the official Perl documentation ;)<br/>&gt; <br/><br/>I&#39;ve pushed a branch on the Perl source tree, and Abigail already<br/>patched the module a bit.<br/>http://perl5.git.perl.org/perl.git/shortlog/refs/heads/book/perlsecret<br/><br/>The &quot;word of warning&quot; still holds. The page is specifically not listed<br/>in the main perl.pod manual page. The idea is to hide it a little, so that<br/>people who know about it can easily point inquiring minds to it, while not<br/>making these &quot;official&quot;.<br/><br/>I also wrote a test script (t/japh/secret.t) and it helped a lot in refining<br/>exactly how and when each of those worked.<br/><br/>-- <br/> Philippe Bruhat (BooK)<br/><br/> &quot;Did I err?&quot; (Groo, in too many issues to count - ...and *YES* he did!)<br/> http://www.nntp.perl.org/group/perl.fwp/2012/04/msg4189.html Tue, 03 Apr 2012 04:31:41 +0000 Re: Secret operators: the documentation by Andrew Savige <br/><br/>I wonder if --$| and $|--, very popular in golf, and described<br/>by japhy as &quot;the magical flip flop variable&quot; at:<br/><br/>&nbsp;http://www.nntp.perl.org/group/perl.fwp/2002/01/msg1367.html<br/><br/>qualifies as a secret operator?<br/><br/>/-\<br/> http://www.nntp.perl.org/group/perl.fwp/2012/04/msg4188.html Tue, 03 Apr 2012 03:44:03 +0000 Re: Secret operators: the documentation by Pau Amma On Mon, April 2, 2012 4:28 pm, Alexis Sukrieh wrote:<br/>&gt; Le 16 mars 2012 12:44, Philippe Bruhat (BooK)<br/>&gt; &lt;philippe.bruhat@free.fr&gt; a &eacute;crit :<br/>&gt;&gt; So,<br/>&gt;&gt;<br/>&gt;&gt; A few years back, I started to write a manual page about Perl secret<br/>&gt;&gt; operators,<br/>&gt; [...]<br/>&gt; I have a question though;<br/>&gt;<br/>&gt; Did you change your mind about the &quot;A word of warning&quot; section? It<br/>&gt; sounds that it won&#39;t fit well in the official Perl documentation ;)<br/><br/>Version I saw last week-end includes:<br/><br/>===<br/>You&#39;re welcome to try these at home, but they might not be safe for work!<br/>===<br/><br/>Is that what you were thinking of?<br/><br/> http://www.nntp.perl.org/group/perl.fwp/2012/04/msg4187.html Mon, 02 Apr 2012 11:14:55 +0000 Re: Secret operators: the documentation by Alexis Sukrieh Le 16 mars 2012 12:44, Philippe Bruhat (BooK)<br/>&lt;philippe.bruhat@free.fr&gt; a &eacute;crit :<br/>&gt; So,<br/>&gt;<br/>&gt; A few years back, I started to write a manual page about Perl secret operators,<br/>&gt; with the goal of getting it into the official Perl documentation at some point.<br/>[...]<br/>&gt; Patches welcome.<br/>&gt;<br/>&gt; When it&#39;s stabilized enough, I&#39;ll send a patch to p5p.<br/><br/>Nice work :)<br/><br/>I have a question though;<br/><br/>Did you change your mind about the &quot;A word of warning&quot; section? It<br/>sounds that it won&#39;t fit well in the official Perl documentation ;)<br/><br/>My two cents!<br/> http://www.nntp.perl.org/group/perl.fwp/2012/04/msg4186.html Mon, 02 Apr 2012 09:29:08 +0000 Re: Secret operators: the documentation by Daniel Bruder Also don&#39;t forget it is expandable, and as it is, still (erotic?) perl :-)<br/><br/>perl -e &#39;print ~~&lt;&gt; =&gt; ~~~~&lt;&gt; =&gt; ~~~~~~&lt;&gt; =&gt; ~~&lt;&gt;+0&#39;<br/><br/><br/>On 16 March 2012 12:44, Philippe Bruhat (BooK) &lt;philippe.bruhat@free.fr&gt;wrote:<br/><br/>&gt; So,<br/>&gt;<br/>&gt; A few years back, I started to write a manual page about Perl secret<br/>&gt; operators,<br/>&gt; with the goal of getting it into the official Perl documentation at some<br/>&gt; point.<br/>&gt;<br/>&gt; Somehow I got interested in that again, and started to really work on it.<br/>&gt; The current work in progress is availabled at:<br/>&gt; https://github.com/book/perlsecret<br/>&gt;<br/>&gt; I&#39;ve already included most of the feedback from the discussions on ~~&lt;&gt;.<br/>&gt;<br/>&gt; Patches welcome.<br/>&gt;<br/>&gt; When it&#39;s stabilized enough, I&#39;ll send a patch to p5p.<br/>&gt;<br/>&gt; --<br/>&gt; Philippe Bruhat (BooK)<br/>&gt;<br/>&gt; Too many believe only in the belief.<br/>&gt; (Moral from Groo The Wanderer #58<br/>&gt; (Epic))<br/>&gt;<br/><br/> http://www.nntp.perl.org/group/perl.fwp/2012/03/msg4185.html Fri, 16 Mar 2012 05:05:37 +0000 Secret operators: the documentation by Philippe Bruhat So,<br/><br/>A few years back, I started to write a manual page about Perl secret operators,<br/>with the goal of getting it into the official Perl documentation at some point.<br/><br/>Somehow I got interested in that again, and started to really work on it.<br/>The current work in progress is availabled at: https://github.com/book/perlsecret<br/><br/>I&#39;ve already included most of the feedback from the discussions on ~~&lt;&gt;.<br/><br/>Patches welcome.<br/><br/>When it&#39;s stabilized enough, I&#39;ll send a patch to p5p.<br/><br/>-- <br/> Philippe Bruhat (BooK)<br/><br/> Too many believe only in the belief.<br/> (Moral from Groo The Wanderer #58 (Epic))<br/> http://www.nntp.perl.org/group/perl.fwp/2012/03/msg4184.html Fri, 16 Mar 2012 04:44:46 +0000 Re: The sperm secret operator: is it new? by Philippe Bruhat On Thu, Mar 15, 2012 at 10:40:17AM +0100, Dmitry Karasik wrote:<br/>&gt; <br/>&gt; &gt; Does that mean I have a dirty mind?<br/>&gt; <br/>&gt; At least not dirtier than the inventor of the =()= (unless that was you ;)<br/><br/>I think the first person using =()= (Randal?) is not the same as<br/>the first person naming it in a Perl context. Both probably have been<br/>invented independently, as goatse was a popular meme at some point, and<br/>people collected references to it. It&#39;s not suprising that a minimalist<br/>ascii-art version appeared. And that it looked like Perl code.<br/><br/>-- <br/> Philippe Bruhat (BooK)<br/><br/> The man who most obeys the king is the man who gets crowned.<br/> (Moral from Groo The Wanderer #13 (Epic))<br/> http://www.nntp.perl.org/group/perl.fwp/2012/03/msg4183.html Fri, 16 Mar 2012 04:43:52 +0000 Re: The sperm secret operator: is it new? by Philippe Bruhat On Thu, Mar 15, 2012 at 03:45:47PM +0100, Dmitry Karasik wrote:<br/>&gt; &gt;&gt;&gt; ~~&lt;&gt;<br/>&gt; &gt;&gt; Looks more like a &quot;kite&quot; operator to me.<br/>&gt; &gt; Does that mean I have a dirty mind?<br/>&gt; <br/>&gt; That means that there&#39;s no such thing as a four-squared sperm! <br/>&gt; <br/><br/>Not that =()= resembles much to a... Hrmpf.<br/><br/>See also http://en.wikipedia.org/wiki/Sperm.<br/>The side view is four-squared enough for me.<br/><br/>The limitations of ASCII shouldn&#39;t limit our imaginations!<br/><br/>-- <br/> Philippe Bruhat (BooK)<br/><br/> Too many believe only in the belief.<br/> (Moral from Groo The Wanderer #58 (Epic))<br/> http://www.nntp.perl.org/group/perl.fwp/2012/03/msg4182.html Thu, 15 Mar 2012 08:35:35 +0000 Re: The sperm secret operator: is it new? by Dmitry Karasik &gt;&gt;&gt; ~~&lt;&gt;<br/>&gt;&gt; Looks more like a &quot;kite&quot; operator to me.<br/>&gt; Does that mean I have a dirty mind?<br/><br/>That means that there&#39;s no such thing as a four-squared sperm! <br/><br/>(ps my previous answer apparently didn&#39;t pass to the list, this is a shorter version of it anyway :)<br/><br/>-- <br/>Sincerely,<br/> Dmitry Karasik<br/><br/> http://www.nntp.perl.org/group/perl.fwp/2012/03/msg4181.html Thu, 15 Mar 2012 07:45:56 +0000 Re: The sperm secret operator: is it new? by Dmitry Karasik <br/>&gt; &gt;&gt; While doing some tests/research on secret operators, I stumbled upon<br/> &gt;&gt; this &gt;&gt; one in my one-liners:<br/> &gt;&gt; &gt;&gt; ~~&lt;&gt;<br/> &gt;&gt; &gt;&gt; Obviously, this should be named &quot;the sperm operator&quot;.<br/> &gt;&gt; Looks more like a &quot;kite&quot; operator to me.<br/>&gt; Does that mean I have a dirty mind?<br/><br/>At least not dirtier than the inventor of the =()= (unless that was you ;)<br/>... anyway I think it&#39;ll be adopted better as &quot;kite&quot;, and well also, where <br/>did you see a four-squared sperm? :) <br/><br/>-- <br/>Sincerely,<br/> Dmitry Karasik<br/><br/> http://www.nntp.perl.org/group/perl.fwp/2012/03/msg4180.html Thu, 15 Mar 2012 07:41:14 +0000 Re: The sperm secret operator: is it new? by Daniel Cutter I would think it means you live in an area where it&#39;s not very windy.<br/><br/>*Daniel Cutter*<br/>s/\b[^a]/\u$&amp;/g,s;$;,;,print for join$,,map{(&#39;acehjklnoprstu&#39;<br/>=~m(.)g,$&quot;)[/\d/?$_:hex]}q(4dbce078c32ae92a6e30152aff)=~m(.)g<br/><br/><br/>Am 15.03.2012 09:22, schrieb Philippe Bruhat (BooK):<br/>&gt; On Thu, Mar 15, 2012 at 06:25:49AM +0100, Dmitry Karasik wrote:<br/>&gt;&gt;&gt;&gt; While doing some tests/research on secret operators, I stumbled upon this<br/>&gt;&gt;&gt;&gt; one in my one-liners:<br/>&gt;&gt;&gt;&gt;<br/>&gt;&gt;&gt;&gt; ~~&lt;&gt;<br/>&gt;&gt;&gt;&gt;<br/>&gt;&gt;&gt;&gt; Obviously, this should be named &quot;the sperm operator&quot;.<br/>&gt;&gt;<br/>&gt;&gt; Looks more like a &quot;kite&quot; operator to me.<br/>&gt;&gt;<br/>&gt; Does that mean I have a dirty mind?<br/>&gt;<br/><br/> http://www.nntp.perl.org/group/perl.fwp/2012/03/msg4179.html Thu, 15 Mar 2012 02:53:30 +0000 Re: The sperm secret operator: is it new? by Philippe Bruhat On Thu, Mar 15, 2012 at 06:25:49AM +0100, Dmitry Karasik wrote:<br/>&gt; &gt;&gt; <br/>&gt; &gt;&gt; While doing some tests/research on secret operators, I stumbled upon this<br/>&gt; &gt;&gt; one in my one-liners:<br/>&gt; &gt;&gt; <br/>&gt; &gt;&gt; ~~&lt;&gt;<br/>&gt; &gt;&gt; <br/>&gt; &gt;&gt; Obviously, this should be named &quot;the sperm operator&quot;. <br/>&gt; <br/>&gt; <br/>&gt; Looks more like a &quot;kite&quot; operator to me.<br/>&gt; <br/><br/>Does that mean I have a dirty mind?<br/><br/>-- <br/> Philippe Bruhat (BooK)<br/><br/> Law is the best deterrent to Justice.<br/> (Moral from Groo The Wanderer #90 (Epic))<br/> http://www.nntp.perl.org/group/perl.fwp/2012/03/msg4178.html Thu, 15 Mar 2012 01:23:08 +0000 Re: The sperm secret operator: is it new? by Dmitry Karasik &gt;&gt; Hi,<br/>&gt;&gt; <br/>&gt;&gt; While doing some tests/research on secret operators, I stumbled upon this<br/>&gt;&gt; one in my one-liners:<br/>&gt;&gt; <br/>&gt;&gt; ~~&lt;&gt;<br/>&gt;&gt; <br/>&gt;&gt; Obviously, this should be named &quot;the sperm operator&quot;. <br/><br/><br/>Looks more like a &quot;kite&quot; operator to me.<br/><br/><br/>-- <br/>Sincerely,<br/> Dmitry Karasik<br/><br/> http://www.nntp.perl.org/group/perl.fwp/2012/03/msg4177.html Wed, 14 Mar 2012 22:25:59 +0000 Re: The sperm secret operator: is it new? by Yitzchak Scott-Thoennes On Wed, Mar 14, 2012 at 3:50 PM, Philippe Bruhat (BooK)<br/>&lt;philippe.bruhat@free.fr&gt; wrote:<br/>&gt; Frankly, I think this could be considered a bug. Both the left-facing<br/>&gt; and right-facing versions of the inchworm on a stick should work on<br/>&gt; all integers in Perl. Complement two arithmetics demand it! Now, the<br/>&gt; question is, how long has this been broken in Perl? Forever?<br/><br/>I don&#39;t consider it a bug. ~ has to either assume signed or unsigned.<br/><br/>You get a choice by whether you do it under the scope of use integer<br/>(implicit: comma signed) or not.<br/> http://www.nntp.perl.org/group/perl.fwp/2012/03/msg4176.html Wed, 14 Mar 2012 16:02:49 +0000 Re: The sperm secret operator: is it new? by Philippe Bruhat On Wed, Mar 14, 2012 at 01:46:34PM -0700, Andrew Savige wrote:<br/>&gt; &gt; [ ~~ vs. scalar ]<br/>&gt; <br/>&gt; The ~~ secret operator is old hat, good ol&#39; inchworm:<br/>&gt; <br/>&gt; &nbsp;http://www.catonmat.net/blog/secret-perl-operators/#inchworm<br/>&gt; <br/>&gt; BooK&#39;s innovation is to add &lt;&gt; and &lt;&gt;+0 to the end of it.<br/>&gt; <br/>&gt; BTW, in addition to inchworm-on-a-stick ~- to subtract one,<br/>&gt; I often use the converse -~ to add one (though only in Ruby<br/>&gt; and Python, not usually Perl). For example, -~1 produces 2<br/>&gt; in Ruby and Python, but -4,294,967,294 in Perl.<br/>&gt; <br/><br/>It works in C too. I was doing some research on secret operators today,<br/>and I discovered the effects of the other inchworm-on-a-stick, and the<br/>fact that both operators are broken for half the integers in Perl.<br/><br/>~- only decrements integers greater than 0 in Perl.<br/>-~ only increments integers lesser than 0 in Perl.<br/><br/>According to Abigail and rgs, it&#39;s probably because ~ must also handle<br/>strings. Abigail and I looked at the source of pp_negate, and it seems<br/>like it does the right thing, so ~ seems to be the culprit. (I see that<br/>tzchak Scott-Thoennes has provided a thorough answer in another mail.)<br/><br/>Frankly, I think this could be considered a bug. Both the left-facing<br/>and right-facing versions of the inchworm on a stick should work on<br/>all integers in Perl. Complement two arithmetics demand it! Now, the<br/>question is, how long has this been broken in Perl? Forever?<br/><br/>-- <br/> Philippe Bruhat (BooK)<br/><br/> The learned man makes a mistake but once... but the truly stupid keep<br/> practicing until they get it right.<br/> (Moral from Groo The Wanderer #75 (Epic))<br/> http://www.nntp.perl.org/group/perl.fwp/2012/03/msg4175.html Wed, 14 Mar 2012 15:50:55 +0000