I'm going to register what I consider to be the most serious reason why -- isnt implemented this way. Reversability. Consider that the rules say any string matching /\A[A-Za-z]*[0-9]*\z/. So this means that 'Zz9' incremented becomes 'AAz0'. Now, what happens when we decrement? Presumbly we should go from 'AAz0' back to 'Zz9'. So we need decrement to remove the leading character. All fine and good. So we decrement a bunch more and eventually get to 'z9'. Now we increment one, and get 'aa0'. So we then end up in the odd situation where -- and ++ are not reversable (++(--'Aa0')!='Aa0') (what the correct name for this? commutable?). It gets even odder, because if we contine down this path we get to '9' which again if we reverse course and increment leaves us at "10" and in the same problem as before but with different colors. And if we contine to decrement we go to -1 and etc as per normal numbers. But what happens if we decrement "A"? If we go to undef as one poster suggested we get a contradiction (in that --0 produces -1 but --'a' produces undef), and after we decrement undef again we get -1 (with a warning thrown in) so now its all a big mess.

++ Zz9 => AAa0 -- AAa0 => Zz9 -- aa0 => z9 -- Aa0 => z9 ++ z9 => aa0 -- a0 => 9 -- 10 => 9 ++ 9 => 10 -- 0 => -1 -- a => undef -- undef => -1

Given all this I can totally understand why -- isnt implemented. I don't think I would have a problem if this behaviour did occur, but I think its strange enough that I can see why it doesn't.


---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

In reply to Re: $a++ allowed by $a-- is not ! why? by demerphq
in thread $a++ allowed by $a-- is not ! why? by abhishes

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.