[tpm] Is there a three-way version of...

Mike Stok mike at stok.ca
Fri May 29 13:10:18 PDT 2009


On May 29, 2009, at 4:01 PM, G. Matthew Rice wrote:

> Madison Kelly <linux at alteeve.com> writes:
>>> a table-like way is adviced.
>>> my $title = $condition1 ? 'result1'
>>>              : $condition2 ? 'result2'
>>>              : $condition 3 ? 'result3'
>>>             # ... more lines here
>
> Yuch.  Looks like C :)
>
> Mine looks similar to another one I saw:
>
>    my $title = {aa => 'bing', bb => 'bang'}->{$key} || 'bong';


Or even use // there if your perl is recent enough, in case you ever  
might have cases involving false but defined strings.

   my $title = { aa => 'bing', bb => 'bang', cc => '0', dd => '' }- 
 >{$key} // 'bong';

Mike

-- 

Mike Stok <mike at stok.ca>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.






More information about the toronto-pm mailing list