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)
In reply to Re: $a++ allowed by $a-- is not ! why?
by jeffa
in thread $a++ allowed by $a-- is not ! why?
by abhishes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |