Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: How the auto-increment operator works?

by zapdos (Acolyte)
on Aug 04, 2020 at 23:36 UTC ( #11120294=note: print w/replies, xml ) Need Help??

in reply to How the auto-increment operator works?

Wait please help me with this again, I don't get why print ++($foo = "Zy"); prints "Zz" and not "Az". Isn't the uppercase "Z" a limit?

And I don't get what "wrap" means either because english is not my native language.

Replies are listed 'Best First'.
Re^2: How the auto-increment operator works?
by choroba (Archbishop) on Aug 04, 2020 at 23:48 UTC
    It's similar to
    print ++($foo = 98)
    which returns 99. Similarly, in "Zy", it first tries to increment from the right, and y -> z is a valid increment which finishes the operation.

    The next word would be AAa, because "z" goes to "a" with a "carry flag", so we need to increment "Z", which goes to "A" with a carry flag, and as there's nothing else to increment to the left, we add "A" (the case is copied from the previous letter).

    Wrap means "to start the round from the beginning again" here.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      Thank you very much brother ;-)
Re^2: How the auto-increment operator works?
by LanX (Cardinal) on Aug 04, 2020 at 23:54 UTC
    > And I don't get what "wrap" means

    The "positions" rotate like in a mechanical calculator, only difference some have characters instead of digits.

    Whenever one wheel finished a full rotation it'll increment the next one to the left.

    Anyway we told you already and I'm tired of this now.

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

      Thank you very much again bro ^_^

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2020-09-30 02:57 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (157 votes). Check out past polls.