Jeff Soules wrote:
Hi all,
Hello,
Am I missing something?
Precedence.
perldoc perlop
I have the following chunks of code:
EX 1:
if ($foo == 1){
$bar = 0;
}else{
$bar = 1;
}
EX 2:
($foo == 1) ?
$bar = 0 :
$bar = 1;
These are logically equivalent, right?
No.
EX 2 should be:
bar = $foo == 1 ? 0 : 1;
But when I've run the latter,
$bar always comes away with a value of 0, regardless of the value of
$foo.
This is particularly confusing, as the following snippet:
EX 3:
($foo == 1) ?
warn "Got 0\n" :
warn "Got 1\n";
is producing the results I expect.
That is usually written as:
warn $foo == 1 ? "Got 0\n" : "Got 1\n";
Am I doing something stupid or missing something obvious?
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/