[tpm] Is there a three-way version of...
Mike Stok
mike at stok.ca
Fri May 29 11:23:41 PDT 2009
On May 29, 2009, at 2:15 PM, Madison Kelly wrote:
> Madison Kelly wrote:
>> my $foo=$bar ? "bing" : "bang";
>> I am probably trying to extend what the above syntax was designed
>> to address, but I am curious. I've got three strings I want to show
>> based on the viewing user's credentials. I know I can use:
>> my $title="";
>> if ($a)
>> {
>> $title="bing";
>> }
>> elsif ($b)
>> {
>> $title="bang";
>> }
>> else
>> {
>> $title="bong";
>> }
>> But it's quite a bit more code.
>> Thanks all!
>> Madi
>
> Sorry to reply to my own question, but I did think of:
>
> my $title="bong";
> $title="bang" if $b;
> $title="bing" if $a;
>
> Though I would still be interested in another way more similar to:
>
> my $foo=$bar ? "bing" : "bang";
>
You can chain ?: for example in the debugger:
main::(-e:1): 1
DB<1> $x = 0; $y = 0
DB<2> print $x ? 'bing' : $y ? 'bang' : 'bong'
bong
DB<3> $x = 0; $y = 1
DB<4> print $x ? 'bing' : $y ? 'bang' : 'bong'
bang
DB<5> $x = 1, $y = 0
DB<6> print $x ? 'bing' : $y ? 'bang' : 'bong'
bing
Layout is left up to you :-)
Mike
> Madi
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
--
Mike Stok <mike at stok.ca>
http://www.stok.ca/~mike/
The "`Stok' disclaimers" apply.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20090529/8dc8a646/attachment.html>
More information about the toronto-pm
mailing list