Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^10: How the auto-increment operator works?

by zapdos (Sexton)
on Aug 02, 2020 at 03:17 UTC ( #11120226=note: print w/replies, xml ) Need Help??


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

"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.
  • Comment on Re^10: How the auto-increment operator works?

Replies are listed 'Best First'.
Re^11: How the auto-increment operator works?
by AnomalousMonk (Bishop) on Aug 02, 2020 at 07:27 UTC

    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

        Thank you too brother. ;-)
      God bless you for making this more clear to me. Domo arigato brother. ^__^
Re^11: How the auto-increment operator works?
by LanX (Cardinal) on Aug 02, 2020 at 13:59 UTC
    > "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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11120226]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2020-11-29 04:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?