Re: fishy conditional expression



Hi Tom,

This is because of operator precedence, && is higher then =. What you
are effectively saying is

@f = (`cat nonExistentFile` && 1==1)

when you probably want

(@f = `cat nonExistentFile`) && 1==1

The code you have ends up assigning to @f an array with a single
element, the empty string. This then evaluates to true in the
conditional statement.

-Jason


On 1/28/07, tom arnall <kloro2006@xxxxxxxxx> wrote:
the following script:

if (@f = `cat nonExistentFile` ) {
print 1;
}

if (@f = `cat nonExistentFile` && (1==1)) {
print 2;
}

gets:

cat: nonExistentFile: No such file or directory
cat: nonExistentFile: No such file or directory
2

seems to me both print statements should be skipped. what am i missing?

tom arnall
north spit, ca


"Relax, the tests extend the compiler."


--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/



.