let me charge in with my new found understanding, limited as it may be.
reverse is unlikely to solve the original problem:
printit($var,$var++);
will produce exactly the same as
printit(reverse($var++,$var)), namely '21'.
Also, the named args would suffer from exactly the same issue - have you tried foo(x => $var, y => $var++) with your construction? After all, it is just another way of writing foo("x",$var,"y",$var++)
From what I gather, Perl always sends things effectively by reference - and that reference is decided in a left-to-right order over the arguments. The thing is, when it sees $var++, it copies the value of $var to a temporary variable, increases $var, but sends a reference to the temp. From there onwards, no changes in $var would have influence on what is sent from the spot of $var++ - nothing else is referencing that temp var. Where $var is, on the other hand, we have already decided to send the reference to $var - but the other terms may also have access to that piece of memory, in which case only what is there at the end of the entire argument list matters. You could try and fix the value in each slot, by sending $var+0, or whatever, but that looks evil
Additionally, if we think about '+' in a functional sort of way, ie $x + $y being actually +($x,$y)... or (+ $x $y), whatever your poison is, then we can solve any sort of conundrums, like what the code below would produce
my $m = 20;
print ++$m + $m++;
(ie, 43), or why, for example, the following are completely different:$var++ + ($var + $var)
and$var++ + $var + $var
perlop seems to be misleading in that sense:
Auto-increment and Auto-decrement:
``++'' and ``--'' work as in C. That is, if placed before a variable, they increment or decrement the variable by one before returning the value, and if placed after, increment or decrement after returning the value.
| [reply] [d/l] [select] |