in reply to Spreadsheet::WriteExcel how to maintain row number
You have at least three options: 1/ reorder the lines so the increment is after the print, 2/ save the $row value prior to increment, 3/ use printf and post increment $row in the argument list.
# 1/ print "Current row number is $row\n"; ++$row; # 2/ my $oldRowValue = $row; ++$row; print "Current row number is $oldRowValue\n"; # 3/ printf "Current row number is %d\n", $row++;
Note that pre (++$row) and post ($row++) increment are different. Post increment behaves like 2/ - the original value is saved, the variable is incremented and the saved value is returned. Pre increment simply increments the variable then returns the result. If your skin gets itchy when you see needless inefficiency then you'll probably avoid post increment ($row++) where a pre increment works just as well, especially as shoving the increment operator out the front makes it easier to see something special is going on.
|
|---|