Fun exercise. So, I will take the challenge.
Now, I'll take a stab at this without doing any cheating. Then I will check my work and place it below in an 'update'.

First, my guess...

my $i = 0; # init $i and set to 0 print ++$i + 1; # answer: 1 (0 + 1) post-operation -> $i == 1 n +ow print $i++ + 1; # answer: 3 (2 + 1) post-operation -> $i == 2 n +ow print $i + $i++; # answer: 5 (2 + 3) post-operation -> $i == 3 n +ow print ++$i + ++$i; # answer: 7 (3 + 4) post-operation -> $i == 7 n +ow print ++$i + $i++ + 1; # answer: 17 (7 + 9 + 1) post-operation -> $i = += 17 now
Update:

Looks like I was way off :(

perl -Mstrict -e ' my $i = 0; print ++$i + 1,"\n"; print $i++ + 1,"\n"; print $i + $i++,"\n"; print ++$i + ++$i,"\n"; print ++$i + $i++ + 1,"\n"; ' 2 2 5 10 14
It looks like I had my pre- and post- backwards. Dumb mistake, really. I seem to have been making a lot of those lately. However, I did enjoy this little exercise.

_ _ _ _ _ _ _ _ _ _
- Jim
Insert clever comment here...


In reply to Re: post-increment/pre-increment blues by snafu
in thread post-increment/pre-increment blues by wil

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.