Hi Everybody,
I'm having trouble figuring out the way the tertiary operator evaluates
and returns data. Here's what I don't get . . .
If I do this:
#!/usr/bin/perl -w
use strict;
my $num=3;
$num==3 ? print "Num equals 3" : print "Num does not equal 3";
I get what I'd expect, "Num equals 3" gets printed.
But, if I do this:
#!/usr/bin/perl -w
use strict;
my $num=3;
my $nextnum;
$num==3 ? $nextnum=4 : $nextnum="unknown" ;
print $nextnum;
It prints "unknown". I'd expect it to print "4" because $num==3 would
evaluate to true.
I've looked in all my books and perldoc but everything seems to say the
same thing: If the operand before ? is true then operand before : is
evaluated and returned, otherwise, the operand after : is evaluated and
returned.
If anyone can clarify the results I'm getting, I'd really appreciate it.
Thanks!
-Dave
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]