[tpm] Is there a three-way version of...
Liam R E Quin
liam at holoweb.net
Fri May 29 11:30:04 PDT 2009
On Fri, 2009-05-29 at 14:15 -0400, Madison Kelly wrote:
> > my $title="";
> > if ($a)
> > {
> > $title="bing";
> > }
> > elsif ($b)
> > {
> > $title="bang";
> > }
> > else
> > {
> > $title="bong";
> > }
Well,
if ($a) {
$title = "bing";
} elsif ($b) {
$title = "bang";
} else {
$title = "bong";
}
is a considerable improvement :)
You can shorten it with,
$title = ("bing", "bang", "bong")[ $a ? 0 : $b ? 1 : 2]
but now no-one can understand it.
> my $title="bong";
> $title="bang" if $b;
> $title="bing" if $a;
is also more compact. Most likely I'd use the
chained if/else with the layout shown, but that's
because I have a background in C, and no shoes. :D
Liam
--
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org www.advogato.org
More information about the toronto-pm
mailing list