In another words:<br><br>$a // $b <br><br>same as<br><br>defined $a ? $a : $b<br><br>The operator was added in Perl 5.10.0<br><br><a href="http://perldoc.perl.org/perldelta.html">http://perldoc.perl.org/perldelta.html</a><br>
<br><pre class="verbatim"><span class="i"></span><span class="i"><br></span></pre><br><br><div class="gmail_quote">On Fri, May 29, 2009 at 4:20 PM, Mike Stok <span dir="ltr"><<a href="mailto:mike@stok.ca">mike@stok.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im"><br>
On May 29, 2009, at 4:17 PM, Madison Kelly wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Mike Stok wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On May 29, 2009, at 4:01 PM, G. Matthew Rice wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Madison Kelly <<a href="mailto:linux@alteeve.com" target="_blank">linux@alteeve.com</a>> writes:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
a table-like way is adviced.<br>
my $title = $condition1 ? 'result1'<br>
: $condition2 ? 'result2'<br>
: $condition 3 ? 'result3'<br>
# ... more lines here<br>
</blockquote></blockquote>
<br>
Yuch. Looks like C :)<br>
<br>
Mine looks similar to another one I saw:<br>
<br>
my $title = {aa => 'bing', bb => 'bang'}->{$key} || 'bong';<br>
</blockquote>
Or even use // there if your perl is recent enough, in case you ever might have cases involving false but defined strings.<br>
my $title = { aa => 'bing', bb => 'bang', cc => '0', dd => '' }->{$key} // 'bong';<br>
Mike<br>
</blockquote>
<br>
I'm not familiar with the '//' operator. It is ... ?<br>
<br>
Madi<br>
</blockquote>
<br></div>
As of perl 5.10 (I think) it is the "defined or" operator which only returns the right hand side if the left hand side is undef, from perlop:<br>
<br>
C−style Logical Defined‐Or<br>
<br>
Although it has no direct equivalent in C, Perl’s "//" operator is<br>
related to its C−style or. In fact, it’s exactly the same as "||",<br>
except that it tests the left hand side’s definedness instead of its<br>
truth. Thus, "$a // $b" is similar to "defined($a) || $b" (except that<br>
it returns the value of $a rather than the value of "defined($a)") and<br>
is exactly equivalent to "defined($a) ? $a : $b". This is very useful<br>
for providing default values for variables. If you actually want to<br>
test if at least one of $a and $b is defined, use "defined($a // $b)".<br>
<br>
The "||", "//" and "&&" operators return the last value evaluated<br>
(unlike C’s "||" and "&&", which return 0 or 1).<div class="im"><br>
<br>
Mike<br>
<br>
-- <br>
<br>
Mike Stok <<a href="mailto:mike@stok.ca" target="_blank">mike@stok.ca</a>><br>
<a href="http://www.stok.ca/%7Emike/" target="_blank">http://www.stok.ca/~mike/</a><br>
<br>
The "`Stok' disclaimers" apply.<br>
<br>
<br>
<br>
<br>
_______________________________________________<br></div><div><div></div><div class="h5">
toronto-pm mailing list<br>
<a href="mailto:toronto-pm@pm.org" target="_blank">toronto-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/toronto-pm" target="_blank">http://mail.pm.org/mailman/listinfo/toronto-pm</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Alexandru Capsa<br>