Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > autoincrement strangeness - please help!

Reply
Thread Tools

autoincrement strangeness - please help!

 
 
Munnki
Guest
Posts: n/a
 
      12-18-2003
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
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      12-18-2003
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


 
Reply With Quote
 
 
 
 
Munnki
Guest
Posts: n/a
 
      12-18-2003
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 |)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Q: Disconnected DataSets - automatic Add/Remove but with Guid Key instead of AutoIncrement int? Sky ASP .Net 2 01-30-2004 09:22 PM
About Rowstate and AutoIncrement fatboycanteen ASP .Net 0 12-12-2003 02:56 AM
Autoincrement database tavle field RA ASP .Net 1 10-22-2003 01:45 PM
Getting the AutoIncrement column data RA ASP .Net 0 10-21-2003 09:52 PM
Re: ViewState + AutoIncrement -- Okay; Session + AutoIncrement -- Not okay Gene Gorokhovsky ASP .Net 0 07-17-2003 02:48 PM



Advertisments