Thank you Steve,William,Ricardo.
Excellent answers.
regards,
Jay
-----Original Message-----
From: Steve Grazzini [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 15, 2004 2:43 PM
To: Jayakumar Rajagopal
Cc: [EMAIL PROTECTED]
Subject: Re: why $a became 6 ?
Jayakumar Rajagopal wrote:
> ($a=3 && $b=6 ) if ( 1 == 1 );
> print " $a $b \n";
>
> Output : 6 6
This is a precedence problem; the "&&" binds more tightly
than the "=" on its left. B::Deparse eliminates some of
the constant expressions, but you can see the result:
% perl -MO=Deparse,-p -e '$a=3 && $b=6'
($a = ($b = 6));
-e syntax OK
Or to break it down another way:
$a = 3 && $b = 6;
$a = 3 && 6;
$a = 6;
Any of these will do what you probably wanted:
$a = 3 and $b = 6;
($a, $b) = (3, 6);
($a = 3) && ($b = 6);
--
Steve
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>