469,898 Members | 1,768 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

autoincrement strangeness - please help!

I am learning Perl and was using the Wrox Learning Perl book that I
found on the web. The author was explaining the autoincrement operator
and try as I might I can't understand this behaviour. The line of code
read...

$a = "9z"; print ++$a, "\n";

Aparently Perl reads in the ranges a-z, A-Z, 0-9 and if it caps off a
range then it will add a digit on the leftmost side and go back to the
beginning of a range ...but i think I misunderstand this as I was
expecting...

munnki@localhost:> 00a

to be output to the shell, as opposed to

munnki@localhost:> 10

i thought that the 9 will have reached it's max and become two zeros
(the start of the next range) and the z would, having reached it's
upper bound, have become an 'a'.

I hope I don't sound too stupid and I know this probably isn't the
most important aspect of the language..but i don't fully understand
this...could someone explain...

thanx
munnki
Jul 19 '05 #1
2 2047
Munnki wrote:
I am learning Perl and was using the Wrox Learning Perl book that I
found on the web. The author was explaining the autoincrement operator
and try as I might I can't understand this behaviour. The line of code
read...

$a = "9z"; print ++$a, "\n";


[Problem with auto-increment magic]

"9z" does not match the pattern "/^[a-zA-Z]*[0-9]*\z/", therefore the magic
is switched off, and the string "9z" is treated as a number which happens to
have the numerical value 9.
Try "z9" instead and you will get the result you are expecting.

For further details please see "perldoc perlop".

jue
Jul 19 '05 #2
thanx Jurgen - i need to start learning about regular expressions and
such - i have been delaying it as all those strange symbols hurt my
eyes :(|)
thanx again
munnki :(|)
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by RA | last post: by
reply views Thread by Neil | last post: by
6 posts views Thread by Dennis | last post: by
4 posts views Thread by Tim | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.