I use the tertiary conditional all the time but I just got some inexplicable
behavior and wanted to see what the group had to say. I have a bit of
code...
my $subject = "Status";
my $returnCode = "o.k.";
print "$subject\n";
$returnCode eq "o.k." ? $subject .= " -OK-" : $subject .= " -FAILED-";
print "$subject\n"; #prints "Status -OK- -FAILED-" <HUH?>
my $subject = "Status";
$subject .= $returnCode eq "o.k." ? " -OK-" : " -FAILED-";
print $subject; #prints "Status -OK-" <RIGHT>
exit();
So I don't understand why the string concatenation is happening in the
'else' part of the first conditional statement. If the return code is
changed then the " -OK-" portion is not appended and just the " -FAILED-"
string gets in there. I can get the first conditional to do what I want by
grouping the concatenations in () but my question is why? Since Perl always
does what it's told, what am I telling it here?
Thanks,
Peter C.