On Jan 27, Dustin Davis said:
>> print ($a = 2, $a++);
>> when i execute this, the output i get it : 32
>print ($a = 2, ++$a); =outputs= 33
>print ($a = 2, $a++); =outputs= 32
Here is why. When you do
print ($a = 2, $a++);
you are calling print() with two arguments. The first one is the return
value of the expression '$a = 2', which is not 2, but is (more or less) an
alias to the value of the variable $a. The second argument is the return
value of the expression '$a++', which is 2. $a++ FIRST returns $a's value
(not an alias to it, but the actual value), and THEN increments $a. This
means, that when the arguments are printed, you get the value of $a and
'2'. The value of $a is 3, because $a++ is evaluated before $a is
The reason print($a = 2, ++$a) prints 33 is because ++$a is pre-increment.
It increments $a's value and then returns an alias to its value.
Jeff "japhy" Pinyan japhy@... http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]