in reply to Secret Perl Operators: the boolean list squash operator, x!!
Your x!! approach is nifty, but it's a little hard to read: the double-negation is confusing unless explained, and the x operator seems to be out of place in this context. I have always found one of these easier to read:
my $uri; foreach ( 'http://example.net/app', $is_admin_link && 'admin', $subsite, $mode, $id, $submode, ) { $uri.="$_/" if ( defined $_ && length($_) ) #omit undef and empties }
If you need to preserve the parts seperately:
my @part = ( 'http://example.net/app', $is_admin_link && 'admin', $subsite, $mode, $id, $submode, ); my $uri; foreach (@parts) { $uri.="$_/" if ( defined $_ && length($_) ) #omit undef and empties }
I prefer these because:
- The logic for inclusion of parts is clear
- It makes it easy to apply a common rule to all components (e.g. URL-ify components before concatenation)
- It avoids repetition of code
<–radiant.matrix–>
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Secret Perl Operators: the boolean list squash operator, x!!
by Aristotle (Chancellor) on Aug 02, 2006 at 14:06 UTC | |
by radiantmatrix (Parson) on Aug 02, 2006 at 14:19 UTC | |
by Aristotle (Chancellor) on Aug 02, 2006 at 15:35 UTC |
In Section
Meditations