Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by AnomalousMonk (Archbishop)
on Aug 02, 2020 at 07:27 UTC ( [id://11120227]=note: print w/replies, xml ) Need Help??


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

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:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^12: How the auto-increment operator works?
by LanX (Saint) on Aug 02, 2020 at 16:02 UTC
    > , 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. ;-)
Re^12: How the auto-increment operator works?
by zapdos (Sexton) on Aug 02, 2020 at 07:48 UTC
    God bless you for making this more clear to me. Domo arigato brother. ^__^

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-24 01:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found