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

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

Replies are listed 'Best First'.
3Re: $a++ allowed by $a-- is not ! why?
by jeffa (Bishop) on Aug 30, 2003 at 17:50 UTC
    "the autoincrement operator was given its special magic so that the range operator can construct things like A..Z"

    This makes so much more sense. :) By the way, working around the lack of -- magic isn't so easy, but working around the .. limitation is, if you can spare the memory overhead for large lists:

    print for reverse 1..99;

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)