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.

Perl is the programming world's equivalent of English

In reply to Re: Spreadsheet::WriteExcel how to maintain row number by GrandFather
in thread Spreadsheet::WriteExcel how to maintain row number by terrykhatri

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.