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

Sorry, I'm not trolling, I'm just a dumbfuck... can you please explain to me why my $foo = "Be"; print ++$foo; prints "Bf" and not "Cf"?

Replies are listed 'Best First'.
Re^7: How the auto-increment operator works?
by AnomalousMonk (Archbishop) on Aug 02, 2020 at 01:00 UTC

    For essentially the same reason that ++75 is 76 and not 86:

    c:\@Work\Perl\monks>perl -wMstrict -le "my $s = '75'; printf qq{++'$s' -> }; ++$s; print qq{'$s'}; " ++'75' -> '76'
    Why would a "carry" ("B" -> "C") be generated by incrementing from "e" to "f"?


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

      Thank you very much. Now I have one more question: why my $foo = "Zz"; print ++$foo; prints "AAa" and not "AAaa"? Since there's two "z" characters and when one "z" character is incremented it produces "aa".
        > > > 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