develooper Front page | perl.perl5.porters | Postings from September 2001

[ID 20010927.005] Auto-Increment doesn't work properly in all cases.

Thread Next
From:
TTTD - Ang Chin Hai 10630629
Date:
September 27, 2001 02:19
Subject:
[ID 20010927.005] Auto-Increment doesn't work properly in all cases.
Message ID:
200109270911.RAA13596@stingray
This is a bug report for perl from chinhai@yahoo.com,
generated with the help of perlbug 1.17 running under perl 5.004.

Hi,

  Read from Perl book on the magic operation on auto-increment, but i
don't think it works for all the cases.

  Below is what i pasted from the book:
-----------------------------------------------------------------------
  The auto-increment operator has a little extra built-in magic. If you
increment a variable that is numeric, or that has ever been used in a 
numeric context, you get a normal increment. If, however, the variable
has only been used in string contexts since it was set, has a value that
is not the null string, and matches the pattern /^[a-zA-Z]*[0-9]*$/, the
increment is done as a string, preserving each character within its range,
with carry:
-----------------------------------------------------------------------

  The following is what i tested out, and the result i expected. However,
some of them are not matched.

                                Expected Result      Actual Result
                                ---------------      -------------
1. print ++($foo='99');              100                100
2. print ++($foo='a9');               b0                 b0
3. print ++($foo='Az');               Ba                 Ba
4. print ++($foo='zz');              aaa                aaa
5. print ++($foo='aZ');               bA                 bA
6. print ++($foo='4z');               5a                  5   <--
7. print ++($foo='6Z');               7A                  7   <--
8. print ++($foo='a1a');             a1b                  1   <--
9. print ++($foo='8b');               8c                  9   <--
10. print ++($foo='b32b');          b32c                  1   <--

  i observed that test #6-#10 match the criterion /^[a-zA-Z]*[0-9]*$/, but
the actual result does not matched!

  For your information, i was using perl 5.003!

thanks,
chin hai


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About