I can not say why -- isn't magical, but it occurred to me that the .. range operator only works going from little to big, and works much in the same way as ++ increments, and with similar magic.

Try the following example:

print 0..9,"\n";

You get 0123456789. Now try the following code:

print 9..0,"\n";

You don't get much of anything at all. Camel says, "The range operator (in a list context) makes use of the magical autoincrement algorithm if the operands are strings."

What isn't stated, but perhaps can be deduced, is that the range operator internally uses the autoincrement function, which when fed strings, behaves magically, and when fed numbers behaves normally. But the point is, the range operators don't use the autodecrement function.

It seems to me (and this is pure speculation) that the autoincrement operator was given its special magic so that the range operator can construct things like A..Z. Again, this is speculation, but .. needed to be able to handle A..Z, .. internally used the autoincrement function, so to make it easy, autoincrement was given magic so that the range operator could become a more useful operator, not limited only to numbers.

Now as for why the range operator doesn't enumerate descending-value lists also, that's another question, and I shouldn't speculate. ;)

Dave

"If I had my life to do over again, I'd be a plumber." -- Albert Einstein


In reply to Re: Re: $a++ allowed by $a-- is not ! why? by davido
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.