autoincrement strangeness - please help!

Discussion in 'Perl' started by Munnki, Dec 18, 2003.

  1. Munnki

    Munnki Guest

    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
    Munnki, Dec 18, 2003
    #1
    1. Advertising

  2. 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
    Jürgen Exner, Dec 18, 2003
    #2
    1. Advertising

  3. Munnki

    Munnki Guest

    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 :(|)
    Munnki, Dec 18, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gene Gorokhovsky
    Replies:
    0
    Views:
    451
    Gene Gorokhovsky
    Jul 17, 2003
  2. RA
    Replies:
    0
    Views:
    330
  3. RA
    Replies:
    1
    Views:
    415
    Darrin J Olson
    Oct 22, 2003
  4. fatboycanteen

    About Rowstate and AutoIncrement

    fatboycanteen, Dec 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    305
    fatboycanteen
    Dec 12, 2003
  5. Sky
    Replies:
    2
    Views:
    437
Loading...

Share This Page