http://qs321.pair.com?node_id=11120224


in reply to Re^8: How the auto-increment operator works?
in thread How the auto-increment operator works?

> > > If a new position is needed it'll adjust to the leftmost group.

> my $foo = "Zz"; print ++$foo; prints "AAa"

The A is a new position the next position to the right - which is causing the "carry" - is an uppercase character A.

> when one "z" character is incremented it produces "aa".

Again the left a is a new position, and the position to the right is a lowercase character.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re^9: How the auto-increment operator works?

Replies are listed 'Best First'.
Re^10: How the auto-increment operator works?
by AnomalousMonk (Archbishop) on Aug 02, 2020 at 02:45 UTC
    ... I'm not trolling ...

    Hmmm... Starting to question this.


    Give a man a fish:  <%-{-{-{-<

Re^10: How the auto-increment operator works?
by zapdos (Sexton) on Aug 02, 2020 at 03:17 UTC
    "The A is a new position the next position to the right - which is causing the "carry" - is an uppercase character."

    "Again the left a is a new position, and the position to the right is a lowercase character."

    I don't get either. This is killing me inside. And AnomalousMonk, no, I'm not trolling I swear for God.

      Perhaps the best thing to do is to remember that in "magic" string incrementation, digit/lowercase/uppercase characters increment from right to left, wrap within themselves, and generate a "carry" into the next left column (or a new left column character if it's already the leftmost (update: and see LanX's reply concerning the "type" of a new column)) when they wrap:

      increment left col ("carry") <- '0' -> '1' -> .. '9' (digits) ^ | | | +----------------+ increment left col ("carry") <- 'a' -> 'b' -> .. 'z' (lower case) ^ | | | +----------------+ increment left col ("carry") <- 'A' -> 'B' -> .. 'Z' (upper case) ^ | | | +----------------+
      String incrementation is pretty stable. I've never known it to change and I doubt it ever will (to preserve backward compatibility), so the best thing I can suggest is to experiment. Whatever results you get are the way "magic" string incrementation works.
      c:\@Work\Perl\monks>perl -e "my $s = 'zZ9'; print qq{'$s' -> }; ++$s +; print qq{'$s'};" 'zZ9' -> 'aaA0' c:\@Work\Perl\monks>perl -e "my $s = 'Zz9'; print qq{'$s' -> }; ++$s +; print qq{'$s'};" 'Zz9' -> 'AAa0' c:\@Work\Perl\monks>perl -e "my $s = 'Zzzz9'; print qq{'$s' -> }; ++ +$s; print qq{'$s'};" 'Zzzz9' -> 'AAaaa0' c:\@Work\Perl\monks>perl -e "my $s = 'zzzz9'; print qq{'$s' -> }; ++ +$s; print qq{'$s'};" 'zzzz9' -> 'aaaaa0' c:\@Work\Perl\monks>perl -e "my $s = 'ZZZZ9'; print qq{'$s' -> }; ++ +$s; print qq{'$s'};" 'ZZZZ9' -> 'AAAAA0'


      Give a man a fish:  <%-{-{-{-<

        > , and generate a "carry" into the next left column (or a new left column character if it's already the leftmost) when they wrap:

        Addendum: And the new left column will be of the same "type" like the old leftmost.

        # leftmost is ... DB<14> $_="z"; print ++$_ # lowercase aa DB<15> $_="z9"; print ++$_ # ... aa0 DB<16> $_="zZ9"; print ++$_ # ... aaA0 DB<17> $_="Zz9"; print ++$_ # uppercase AAa0 DB<18>

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

        God bless you for making this more clear to me. Domo arigato brother. ^__^
      > "The A is a new position the next position to the right - which is causing the "carry" - is an uppercase character."

      > I don't get either

      Please see Carry (arithmetic)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery