Thread Seriennummer (Buchstaben) hochzählen (7 answers)
Opened by Gustl at 2014-01-27 14:27

pq
 2014-01-29 12:10
#173266 #173266
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
nein, da geht leider nur ++
da musst du wohl doch eine umständlichere variante implementieren

Quote
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:

print ++($foo = "99"); # prints "100"
print ++($foo = "a0"); # prints "a1"
print ++($foo = "Az"); # prints "Ba"
print ++($foo = "zz"); # prints "aaa"

"undef" is always treated as numeric, and in particular is changed to 0 before incrementing (so that a post‐increment of an undef value will return 0 rather than "undef").

The auto‐decrement operator is not magical.
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread Seriennummer (Buchstaben) hochzählen