--- Rob Dixon <[EMAIL PROTECTED]> wrote: > Derek B. Smith wrote: > > --- "Dr.Ruud" <[EMAIL PROTECTED]> wrote: > > > >> Norbert Preining schreef: > >> > >>> The Perl Book says: Auto increment and decrement > >> work as in > >>> C. So if I take this C program: > >>> #include <stdio.h> > >>> #include <stddef.h> > >>> int main() { > >>> int a; > >>> int b; > >>> a=3; > >>> b=(++a)+(a++); > >>> printf("b=%d\n",b); > >>> } > >>> it prints b=8. > >>> > >>> When I do the same in perl: > >>> $a = 3; > >>> $b = (++$a) + ($a++); > >>> print "b=$b\n"; > >>> > >>> It prints b=9. > >>> > >>> I checked with a friend and Java behaves like C > >> and prints 8. > >> > >> $ perl -wle ' > >> $a = 3; > >> $b = 0 + (++$a) + ($a++); > >> print "b=$b\n"; > >> ' > >> b=8 > >> :) > > > > > > Lessons learned.... > > > > always initialize your variables to zero. : ) > > > That's not initialising the variable, its, sort of, > initialising the expression. > > $b = 0; > $b += ++$a + $a++; > > (the parentheses are irrelevant) also gives 9. This > looks like a bug to me, and > v5.6 does it as well. Unless anyone can persuade me > that this is correct > behaviour? > > Rob >
No I cannot, you are correct...init the expression. : ) Have to remember this one. I tried in on Active Perl 5.8.8 and Cygwin 5.8.7 and it is behaving the same way. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>