Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1012691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:59:03+00:00 2026-05-16T09:59:03+00:00

I do not understand autoincrementing letters in Perl. This example seems perfectly understandable: $a

  • 0

I do not understand autoincrementing letters in Perl.

This example seems perfectly understandable:

$a = 'bz'; ++$a;
ca #output

b gets incremented to c. There is nothing left for z to go to, so it goes back to a (or at least this is how I see the process).

But then I come across statements like this:

$a = 'Zz'; ++$a;
AAa #output

and:

$a = '9z'; ++$a;
10 #output

Why doesn’t incrementing Zz return Aa? And why doesn’t incrementing 9z return 0z?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T09:59:03+00:00Added an answer on May 16, 2026 at 9:59 am

    To quote perlop:

    If, however, the variable has been
    used in only string contexts since it
    was set, and has a value that is not
    the empty string and matches the
    pattern /^[a-zA-Z]*[0-9]*\z/, the
    increment is done as a string,
    preserving each character within its
    range, with carry.

    The ranges are 0-9, A-Z, and a-z. When a new character is needed, it is taken from the range of the first character. Each range is independent; characters never leave the range they started in.

    9z does not match the pattern, so it gets a numeric increment. (It probably ought to give an “Argument isn’t numeric” warning, but it doesn’t in Perl 5.10.1.) Digits are allowed only after all the letters (if any), never before them.

    Note that an all-digit string does match the pattern, and does receive a string increment (if it’s never been used in a numeric context). However, the result of a string increment on such a string is identical to a numeric increment, except that it has infinite precision and leading zeros (if any) are preserved. (So you can only tell the difference when the number of digits exceeds what an IV or NV can store, or it has leading zeros.)

    I don’t see why you think Zz should become Aa (unless you’re thinking of modular arithmetic, but this isn’t). It becomes AAa through this process:

    1. Incrementing z wraps around to a. Increment the previous character.
    2. Incrementing Z wraps around to A. There is no previous character, so add the first one from this range, which is another A.

    The range operator (..), when given two strings (and the left-hand one matches the pattern), uses the string increment to produce a list (this is explained near the end of that section). The list starts with the left-hand operand, which is then incremented until either:

    1. The value equals the right-hand operand, or
    2. The length of the value exceeds the length of the right-hand operand.

    It returns a list of all the values. (If case 2 terminated the list, the final value is not included in it.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is one thing that I do not understand... Imagine you have a text
There was an interesting question in a practice test that I did not understand
There is a difference in the description on MSDN, however, I do not understand
I have encountered a rather odd error that I do not understand. I created
I read the SDK document, but can not understand some details, need some help.
I do not quite understand the difference between a C# reference and a pointer.
How universally is the C99 standard supported in today's compilers? I understand that not
I understand the reason behind not auto refreshing your .dbml (Linq2Sql), .edmx (Linq2Entities) or
I understand the reflection API (in c#) but I am not sure in what
I'm not completely sure I understand the workflow way of doing things, but if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.