Precision in language is crucial to writing your code. In this case, you're saying a present value is that value, post-incremented. Strictly speaking, that's true, but writing the code in this fashion is apt to trip the unwary -- author included:

#!/usr/bin/perl =w use strict; #1137973 my $number=8; for(my $i=0; $i<3; $i++) { print "present value of \$i is $i and the number is: $number \n"; print " now printing \$number++: " . $number++ . "\n"; # NOTE O +UTPUT! print "!! NOW, NOT EARLIER the post-increment occurs AFTER Ln 10\ +n"; print " and after post-increment, \$i is STILL $i but number +is: $number\n\-----------\n"; } =head present value of $i is 0 and the number is: 8 now printing $number++: 8 # ie, unchanged! !! NOW, NOT EARLIER the post-increment occurs AFTER Ln 10 and after post-increment, $i is STILL 0 but number is: 9 ----------- present value of $i is 1 and the number is: 9 now printing $number++: 9 !! NOW, NOT EARLIER the post-increment occurs AFTER Ln 10 and after post-increment, $i is STILL 1 but number is: 10 ----------- present value of $i is 2 and the number is: 10 now printing $number++: 10 !! NOW, NOT EARLIER the post-increment occurs AFTER Ln 10 and after post-increment, $i is STILL 2 but number is: 11 ----------- =cut

You're cheese-paring the size of your script by a few bytes at the expense of clarity; better to post-increment in a standalone line of code -- for clarity.

UPDATE: ... or, as Athanasius pointed out in a message, a (standalone) pre-increment (++$number)could also be used effectively ... but that would REALLY require precise language... as in something like "the next number is: " or maybe "oops, off by one."


In reply to Re: usage of "my" keyword (quibble re clarity) by ww
in thread usage of "my" keyword by ravi45722

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.