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:
- Incrementing
z
wraps around to a
. Increment the previous character.
- 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:
- The value equals the right-hand operand, or
- 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.)