a pointer to the documentation that garantees things will happen this way.

There is none.

9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. [...]
If you want guarantees, do not use Perl.

But it is nowhere specified that $i will be incremented before or after an assignment.

$i = $i++ is deparsed to ($i = ($i++)). Having $i tied and assigning to another tied variable tells me the increment happens before the assignment.

look up the discussion of ++ in perlop. It says that it works as in C

Perlop is wrong. Did the authors of Perl re-create all compiler/platform specific postincrement issues that exist in C? If not, how can its behaviour ever be the same?

nowhere specified that $i will be incremented before or after an assignment

perl's sourcecode is the specification - MANY things are not defined in the perldocs. And fortunately, this is compiler/platform independent. Anyway. Here's your specification:

PP(pp_postinc) { dSP; dTARGET; if (SvTYPE(TOPs) > SVt_PVLV) DIE(aTHX_ PL_no_modify); sv_setsv(TARG, TOPs); if (!SvREADONLY(TOPs) && SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvP +OK(TOPs) && SvIVX(TOPs) != IV_MAX) { ++SvIVX(TOPs); SvFLAGS(TOPs) &= ~(SVp_NOK|SVp_POK); } else sv_inc(TOPs); SvSETMAGIC(TOPs); if (!SvOK(TARG)) sv_setiv(TARG, 0); SETs(TARG); return NORMAL; }
PP(pp_preinc) { dSP; if (SvTYPE(TOPs) > SVt_PVLV) DIE(aTHX_ PL_no_modify); if (!SvREADONLY(TOPs) && SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvP +OK(TOPs) && SvIVX(TOPs) != IV_MAX) { ++SvIVX(TOPs); SvFLAGS(TOPs) &= ~(SVp_NOK|SVp_POK); } else /* Do all the PERL_PRESERVE_IVUV conditionals in sv_inc */ sv_inc(TOPs); SvSETMAGIC(TOPs); return NORMAL; }
Pay special attention to dTARGET, sv_setsv and SETs in the postinc. As you can see, Perl does not delay the increment, but it does save the old value. (Which is because Perl can not optimise the same way C compilers do. At compile time, Perl cannot be sure if $i is a normal scalar or something special.)

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.


In reply to Re: Re: Incrementing a Hash Value by Juerd
in thread Incrementing a Hash Value by arunhorne

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.