note
BlaisePascal
From the "gratuitous use of grep" club...
<code>
$string = "$a where " . join ' and ',grep {$_} ($b,$c);
</code>
Explanation: Read this from right-to-left.
The <tt>grep</tt> takes as arguments a block of code
(or a sub) and a list of items and return just the items
in the list which the block of code is true for. In this
case, the block of code is simply <tt>$_</tt>, so grep
returns all items in the list <tt>($b,$c)</tt> which are
true (not undef, '', 0, or '0'). The <tt>join</tt> then takes those
true items, and combines that list with ' and '. If there
only one item, join omits the ' and '. It then concatenates
the resulting string of 'where' clauses to the string formed by
"$a where ", to get the resulting string.
34515
34515