<?xml version="1.0" encoding="windows-1252"?>
<node id="564869" title="Re^2: Secret Perl Operators: the boolean list squash operator, x!!" created="2006-07-31 16:55:06" updated="2006-07-31 12:55:06">
<type id="11">
note</type>
<author id="114691">
Aristotle</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;p&gt;obscure implementation details&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Disagree. The shape of booleans in Perl 5 is specified behaviour, and is only going to become more explicit in Perl 6.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;I would instead suggest that a clearer, more maintainable version might be &lt;tt&gt;($string) x ($cond ? 1 : 0)&lt;/tt&gt;&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;If you’re using a ternary anyway, why would you want to throw in an &lt;tt&gt;x&lt;/tt&gt; op? All that does is lose the shortcircuiting, make the code longer, and force some extraneous parens. Just do all the work using the ternary: &lt;tt&gt;$cond ? $string : ()&lt;/tt&gt;&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;I don’t find either of your original “problem” examples to be particularly onerous&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;I’d never use the [doc://push] version. The one with ternaries doesn’t look onerous because there are so many conditional bits that you have no hope of putting it all on a single line anyway, and the lists are simpler than the conditionals, and it’s highly regular, and all. I was trying to come up with an example that can’t be simplified using [doc://grep].&lt;/p&gt;

&lt;p&gt;I can’t recall the exact code that led me to post the thread on &lt;tt&gt;perl6-users&lt;/tt&gt; which led Larry to nudge me in this direction, but it was a case of injecting a single list into the arguments of a one-liner [doc://join], where precedence forced me to parenthesise things, so the version using the ternary absolutely was more ornery than it should have been. With such a short list, it’s more annoying than the example I gave in the root node, because nothing really helps – putting it on a single line makes it unwieldy, breaking it into multiple lines makes it breathlessly verbose, using an extra temporary looks hackish. Sticking an &lt;tt&gt;x!!&lt;/tt&gt; wouldn’t have been ideal, but would certainly read better than all the alternatives.&lt;/p&gt;

&lt;p align="right" class="pmsig pmsig-114691"&gt;&lt;i&gt;Makeshifts last the longest.&lt;/i&gt;&lt;/p&gt;</field>
<field name="root_node">
564792</field>
<field name="parent_node">
564865</field>
</data>
</node>
