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

It would output "\`\n" if it acted upon the ordinal value.
  • Comment on Re: Re: $a++ allowed by $a-- is not ! why?

Replies are listed 'Best First'.
Re: $a++ allowed by $a-- is not ! why?
by Abigail-II (Bishop) on Sep 02, 2003 at 14:14 UTC
    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.

        Sorry, totally wrong, it should be:
        'ab' = (1*(26**1)) + (2*(26**0)) 'ab' -- = (1*(26**1)) + ((2*(26**0)) - (1*(26*0))) = (1*(26**1)) + (1*(26**0)) = 'aa'
        But ideally a string containing only alphanumerics with an alphabet in upper and lower case could be handled as a Base 62 number which would also allow decrement, because the question with the above is how does it handle numerics and upper case. Base 62 would solve that.