in reply to Re: map confusion
in thread map confusion

Thank-you. However even with ++$_, @array is still affected in the first case, but not with *. Any thoughts on why?

Replies are listed 'Best First'.
Re^3: map confusion
by FreeBeerReekingMonk (Deacon) on Dec 16, 2015 at 00:04 UTC

    Let's say you have a variable $A and you do this:
    $A = 5; $B = $A++; print $A; # prints out 6. $B is 5
    $A = 5; $B = ++$A; print $A; # prints out 6. $B is 6
    $A = 5; $B = $A*2; print $A; # prints out 5. $B is 10
    $A = 5; $B = $A+1; print $A; # prints out 5. $B is 6


    Because ++ changes the original AFTER the operation, and mutiplication just returns the result, without modifying the original.