<?xml version="1.0" encoding="windows-1252"?>
<node id="565228" title="Re: Secret Perl Operators: the boolean list squash operator, x!!" created="2006-08-02 10:01:29" updated="2006-08-02 06:01:29">
<type id="11">
note</type>
<author id="375088">
radiantmatrix</author>
<data>
<field name="doctext">
&lt;p&gt;Your &lt;c&gt;x!!&lt;/c&gt; approach is nifty, but it's a little hard to read: the double-negation is confusing unless explained, and the &lt;c&gt;x&lt;/c&gt; operator seems to be out of place in this context.  I have always found one of these easier to read:

&lt;code&gt;
my $uri;
foreach ( 
   'http://example.net/app',
   $is_admin_link &amp;&amp; 'admin',
   $subsite, 
   $mode, 
   $id, 
   $submode,
) {
   $uri.="$_/" if ( defined $_ &amp;&amp; length($_) ) #omit undef and empties
}
&lt;/code&gt;

&lt;p&gt;If you need to preserve the parts seperately:

&lt;code&gt;
my @part = ( 
   'http://example.net/app', 
   $is_admin_link   &amp;&amp; 'admin',
   $subsite,
   $mode,
   $id,
   $submode,
);

my $uri; 
foreach (@parts) { 
   $uri.="$_/" if ( defined $_ &amp;&amp; length($_) ) #omit undef and empties
} 
&lt;/code&gt;

&lt;p&gt;I prefer these because:&lt;ol&gt;
&lt;li&gt;The logic for inclusion of parts is clear
&lt;li&gt;It makes it easy to apply a common rule to all components (e.g. URL-ify components before concatenation)
&lt;li&gt;It avoids repetition of code
&lt;/ol&gt;

&lt;!-- 
&lt;p&gt;&lt;small&gt;&lt;b&gt;Updates:&lt;/b&gt;&lt;ul type='square'&gt;
&lt;li&gt;date : desc&lt;/li&gt;
&lt;/ul&gt;&lt;/small&gt;&lt;/p&gt;
--&gt;

&lt;div class="pmsig"&gt;&lt;div class="pmsig-375088"&gt;
&lt;small&gt;
&lt;small&gt;&lt;font color='#000000'&gt;&amp;lt;&lt;/font&gt;&lt;font color='#1a1a1a'&gt;&amp;ndash;&lt;/font&gt;&lt;font color='#343434'&gt;r&lt;/font&gt;&lt;font color='#4e4e4e'&gt;a&lt;/font&gt;&lt;font color='#686868'&gt;d&lt;/font&gt;&lt;font color='#828282'&gt;i&lt;/font&gt;&lt;font color='#9c9c9c'&gt;a&lt;/font&gt;&lt;font color='#b6b6b6'&gt;n&lt;/font&gt;&lt;font color='#d0d0d0'&gt;t&lt;/font&gt;&lt;font color='#eaeaea'&gt;.&lt;/font&gt;&lt;font color='#d0d0d0'&gt;m&lt;/font&gt;&lt;font color='#b6b6b6'&gt;a&lt;/font&gt;&lt;font color='#9c9c9c'&gt;t&lt;/font&gt;&lt;font color='#828282'&gt;r&lt;/font&gt;&lt;font color='#686868'&gt;i&lt;/font&gt;&lt;font color='#4e4e4e'&gt;x&lt;/font&gt;&lt;font color='#343434'&gt;&amp;ndash;&lt;/font&gt;&lt;font color='#1a1a1a'&gt;&amp;gt;&lt;/font&gt;&lt;/small&gt;
&lt;!--&amp;lt;-&lt;/small&gt;&lt;b&gt;radiant&lt;/b&gt;.&lt;b&gt;matrix&lt;/b&gt;&lt;small&gt;-&amp;gt;&lt;/small--&gt;
&lt;br&gt;&lt;a href='http://radiantmatrix.org/'&gt;A collection of thoughts and links from the minds of geeks&lt;/a&gt;
&lt;br&gt;&lt;em&gt;The Code that can be seen is not the true Code&lt;/em&gt;
&lt;br&gt;&lt;em&gt;I haven't found a problem yet that can't be solved by a well-placed [http://en.wikipedia.org/wiki/Trebuchet|trebuchet]&lt;/em&gt;
&lt;/small&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
564792</field>
<field name="parent_node">
564792</field>
</data>
</node>
