Hi monks!,
Last week, I need a chunk of code that autoincrement a string magically, as '++'; but not holding the first character.
So "sa9876" would result "sa9877",
"sa9999" would result "sb9999"
and "sz9999" would result "saa0000"
At first, I wrote this code:
my($f,@r)=split//,$_; my$l=join"",@r; ++$l; $_=$f.$l; print $_;
So I "autoincrement in my way" $_
Is the code too long?
I think it is, I could make it shorter...
Is this a golf?
Yes, it is...
This is second attempt
#23456789#123456789#1234567 ($_,$b)=/(.)(.*)$/;$_.=++$b
Note:I would like not to use variables as $b, cause it would be predeclared if use strict is used, but I can't autoincrement $DIGIT (there are read-only)
Who plays the hole?

UPDATE:
danger, great!, I didn't think in substr!
UPDATE:
Thanks crazyinsomniac, I didn't know that $a and $b doesn't need to be predeclared.
I've played with sort and is magical too. It use $a and $b but restore them at the end.

Update!
anarion's code: Brackets can be pulled...
++substr$_,1
Example:
perl -le '$_=sa9999;++substr$_,1;print'


Hopes
$_=$,=q,\,@4O,,s,^$,$\,,s,s,^,b9,s, $_^=q,$\^-]!,,print

Replies are listed 'Best First'.
Re: Other Magical autoincrement
by danger (Priest) on Dec 27, 2001 at 15:09 UTC

    Here's one a tad shorter:

    #2345678901234 substr($_,1)++