"R. Joseph Newton" wrote: > Andrew Gaffney wrote: > > > WC -Sx- Jones wrote: > > > What is happening here -
> > That is a damn good question. I'm not sure what results I was expecting when I ran > > it, but > > it sure wasn't this: > > > > 3 > > 15 > > 63 > > 255 > I'm stumped, also.I would have expected progressive 2**n -1 As far as I can tell, > the test > in the conditional operation should always evaluate true. The preccedence of += and > postfix > decrement should have decremented after the value had doubled. After printing, the > number > should be re-incremented Sheesh--there no damn short-circuit on the evaluation!! > Well, I'll > be darned! Only one of the two alternatives will be assigned, but both are > evaluated. ... > It really is an object lesson in the dangers of using lvalued functions in void context, for their side effects. The conditional operator is meant to return one of its alternative values. Unlike the or and and operators, though, it does not short-circuit its evaluation. It seems to evaluate the expressions for both alternatives, and then assign one or the other depending on the value of the test. Since the conditiional operator is used in void context, there is no lvalue to receive the primary product of the operation. The side effects here are the whoe show. > while(1) { > if (++$count) { > $count += $count; > $count--; > my $alternative_yes = $count; > $count += $count; > $count++; > my $alternative_no = $count; > } else { > die "The impossible has happened! $!"; > } > print "$count\n"; exit if $count > 60_000; > sleep 1; > } Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>