On Tue, Mar 30, 2004 at 04:57:07PM -0800, R. Joseph Newton wrote: > Jeff 'japhy' Pinyan wrote: > > > On Mar 30, WC -Sx- Jones said: > > > > >my $count; > > > > > >while(1) { > > > (++$count) ? $count += $count-- : $count += $count++; > > > > > > print "$count\n"; exit if $count > 60_000; > > > sleep 1; > > >} > > > > The main problem is the PRECEDENCE. Your ? : line is run like so: > > > > ((++$count) ? ($count += $count--) : $count) += $count++; > > Have you tested this? I don't see the precedence issue happening here. Could > you try duplicating these reults with code explicitly specifying the precedence > you show? I do not think you are going to find that the outer parentheses you > show represent the actual precedence. Remember that the ? and : are not > different operators, but different parts of the same operator. If the += > operator has a higher precedence than ?, it will also have a higher precedence > than :.
$ perl -MO=Deparse,-p -e '(++$count) ? $count += $count-- : $count += $count++;' (((++$count) ? ($count += ($count--)) : $count) += ($count++)); -e syntax OK Jeff is spot on, as usual. If this were C, I would be muttering something about sequence points and undefined behaviour right now. Perl is not quite so strict in that regard, but you can still get unexpected results by breaking some of those rules, so it is generally best not to. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>