Re: fishy conditional expression
- From: jroth2@xxxxxxxx ("Jason Roth")
- Date: Mon, 29 Jan 2007 13:27:03 -0600
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/
- References:
- libgdbm
- From: Daniel D Jones
- fishy conditional expression
- From: Tom Arnall
- libgdbm
- Prev by Date: fishy conditional expression
- Next by Date: Re: fishy conditional expression
- Previous by thread: fishy conditional expression
- Next by thread: Re: fishy conditional expression
- Index(es):