in reply to $a++ allowed by $a-- is not ! why?
The auto-increment operator has a little extra builtin magic to it. 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 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 auto-decrement operator is not magical.print ++($foo = '99'); # prints '100' print ++($foo = 'a0'); # prints 'a1' print ++($foo = 'Az'); # prints 'Ba' print ++($foo = 'zz'); # prints 'aaa'
UPDATE:
Sorry for not saying this originally ... but i have no
idea why the auto-decrement operator is not magical. But,
how often (japh's not included) do you need to decrement
a string? Incrementing strings is a handy way to get a new
value, say for an identifier. When you need a new id, just
increment. I may not be right about this, but i am guessing
that this was the movitation behind making the
auto-increment operator magical.
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: $a++ allowed by $a-- is not ! why?
by davido (Cardinal) on Aug 30, 2003 at 17:17 UTC | |
by jeffa (Bishop) on Aug 30, 2003 at 17:50 UTC | |
|
Re: Re: $a++ allowed by $a-- is not ! why?
by abhishes (Friar) on Aug 30, 2003 at 16:46 UTC | |
by Abigail-II (Bishop) on Aug 31, 2003 at 09:39 UTC | |
by Anonymous Monk on Sep 02, 2003 at 13:52 UTC | |
by Abigail-II (Bishop) on Sep 02, 2003 at 14:14 UTC | |
by Anonymous Monk on Sep 02, 2003 at 16:07 UTC | |
|