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

However, why is the auto-decrement operator not magical in nature?

Suppose it was, what would the following print:

my $a = "a"; $a --; print $a, "\n";

Abigail

Replies are listed 'Best First'.
Re: Re: $a++ allowed by $a-- is not ! why?
by Anonymous Monk on Sep 02, 2003 at 13:52 UTC
    It would output "\`\n" if it acted upon the ordinal value.
      It would output "\`\n" if it acted upon the ordinal value.

      But since ++ doesn't act on ordinal values, why should --? Furthermore, what should:

      my $a = "a"; $a --; print $a;

      print on an EBCDIC platform?

      Abigail

        It depends upon which EBCDIC variant the platform was running but IIRC with Western European platforms it would be a speech mark. But I take your point.

        But since the sequence is a b c d e f g h i etc. why not apply magic to the -- operation and use the numbers as Base 26.

        So a decrement would of ab would become:

        'ab' = (1*(25*1))+(2*(25*0)) 'ab'-- = (1*(25*1))+((2*(25*0))-(1*(25*0))) = (1*(25*1))+((1*(25*0)) = 'aa'

        Then 'a'-- would always = -1 and decrements become OK with a predictable behaviour.