Hi Shawn!
On Monday 29 Mar 2010 17:19:36 Shawn H Corey wrote:
> On Mon, 29 Mar 2010 10:02:15 -0400
>
> Jeff Soules <[email protected]> wrote:
> > ($foo == 1) ?
> >
> > $bar = 0 :
> > $bar = 1;
> >
> > Am I doing something stupid or missing something obvious?
>
> ($foo == 1) ?
> ( $bar = 0 ) :
> ( $bar = 1 );
>
> Assignment has lower precedence than ?: It is done last. What you
> wrote above is:
>
> (($foo == 1) ?
> $bar = 0 :
> $bar ) = 1;
>
> Which assigns 1 to $bar regardless of what $foo is.
Thanks for the clarification. I suspected something of this sort was the case.
Whenever I don't remember what the operator precedence is, I always add a few
parentheses. I still often tend to do something like:
{{{
if (($age > 18) && ($name eq "Catherine"))
}}}
(I.e: put parentheses around the clauses of if statements, even though they
are not needed or I could use the ultra-low-precedence "and"/"or"/etc.)
Regards,
Shlomi Fish
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
My Aphorisms - http://www.shlomifish.org/humour.html
Deletionists delete Wikipedia articles that they consider lame.
Chuck Norris deletes deletionists whom he considers lame.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/