in reply to Re: What does the ternary statement actually do?
in thread What does the ternary statement actually do?
As an alternative, you might want to use:printf ("%d %s%s\n", $count, "cat", ($count==1)?"":"s"); printf ("%d %s%s\n", $count, "cact", ($count==1)?"us":"i"); printf ("%d %s%s\n", $count, "Elvi", ($count==1)?"s":"i");
Or perhaps as a method:print $count, "cat", (($count==1)?"":"s"), "\n"; print $count, "cact", (($count==1)?"us":"i"), "\n"; print $count, "Elvi", (($count==1)?"s":"i"), "\n";
sub quantize { my ($quantity, $singular, $plural) = @_; return (1==$quantity)? $singular : $plural; } $count = 2; print "$count @{[quantize($count,'cat','cats')]}\n";
|
|---|