in reply to Mr. Ternary is greater than Mrs. If Else
printf("The answer is %s\n", defined($ans) ? $ans : "unknown");'
or
$ans = defined($ans) ? $ans : "unknown";
This is left over from C programming days. I stopped at the first known construct. It seems efficient versus this:
printf("The answer is ");
if (defined($ans))
{
printf("%s\n", $ans);
}
else
{
printf("unknown\n");
}
I would not have a tendency to use it on multi-line constructs as shown in other examples in this thread because the ? and : tend to get lost.
|
|---|