It basically looks like we're talking about switch statements. An alternate method of doing the same thing would be as follows, though I'm not sure how expensive it is:<br><br>$a = "";<br>$a = $b if $a = "";<br>
$a = $c if $a = "";<br>$a = $d if $a = "";<br>...<br>$a = "default" if $a = "";<br><br><div class="gmail_quote">On Fri, May 29, 2009 at 4:43 PM, John Macdonald <span dir="ltr"><<a href="mailto:john@perlwolf.com">john@perlwolf.com</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">On Fri, May 29, 2009 at 04:20:48PM -0400, Mike Stok wrote:<br>
> As of perl 5.10 (I think) it is the "defined or" operator which only<br>
> returns the right hand side if the left hand side is undef, from perlop:<br>
><br>
> C−style Logical Defined$B!>(BOr<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>
> "||",<br>
> except that it tests the left hand side’s definedness instead of<br>
> its<br>
> truth. Thus, "$a // $b" is similar to "defined($a) || $b" (except<br>
> that<br>
> it returns the value of $a rather than the value of<br>
> "defined($a)") and<br>
> is exactly equivalent to "defined($a) ? $a : $b". This is very<br>
> useful<br>
> for providing default values for variables. If you actually want<br>
> to<br>
> test if at least one of $a and $b is defined, use "defined($a //<br>
> $b)".<br>
><br>
> The "||", "//" and "&&" operators return the last value evaluated<br>
> (unlike C’s "||" and "&&", which return 0 or 1).<br>
<br>
</div>This is especially useful for setting a value that can come from<br>
multiple optional locations, and using the first one that was<br>
actually provided:<br>
<br>
$foo = $opt{foo} || $ENV{PROG_FOO} || $rc_opts{foo} || 'default';<br>
<br>
and, as Mike said, this will still take the first one found even<br>
if the explicitly provided value is 0 or ''. e.g.:<br>
<br>
prog --foo=0<br>
<br>
The || operator would skip this setting (because it's false) and<br>
go on to getting the setting of foo from the alternate sources.<br>
<div><div></div><div class="h5">_______________________________________________<br>
toronto-pm mailing list<br>
<a href="mailto:toronto-pm@pm.org">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>J. Bobby Lopez<br>Web: <a href="http://jbldata.com/">http://jbldata.com/</a><br>Twitter: <a href="http://www.twitter.com/jbobbylopez">http://www.twitter.com/jbobbylopez</a><br>
<br>