in reply to pre v.s. post (increment/decrement)

What is the difference in using post as opposed to pre for increment/decrement.

A post-increment (or decrement) is done after the containing expression is evaluated. A pre-increment (or decrement) is done prior to the containing expression being evaluated. An example will help.

$ perl -le 'my $x = 0; print $x++' 0 $ perl -le 'my $x = 0; print ++$x' 1

As for when you might want to use one instead of another, the one thing that springs to mind is when you want to increment or decrement an array index within the expression using it. The code below is contrived and I'd never actually do it like this, but it illustrates the point.

# Fill @array with ten random numbers. my $i = 0; $array[$i++] = rand() while $i < 10;
If we'd used a pre-increment, we would have populated the indices from 1 to 10 rather than 0 to 9 as desired.

-sauoq
"My two cents aren't worth a dime.";