in reply to incrementing strings

Strings don't increment this way, if what you are trying to do is take
$alias = "johnq.smith1"; $alias++;
and turn $alias into
"johnq.smith2"
. What you'll need to do is save the digits into a temporary variable, increment them, then append to the digitless string:
$alias = "johnq.smith1"; if ($alias =~ s/(\d+$)//) { $alias .= $1++; # $alias is now "johnq.smith2" }
There are, of course, other ways to achieve this, but not via directly incrementing a string.

Update: Ignore my response. Of course you can increment strings this way. Is it friday yet?

Replies are listed 'Best First'.
Re^2: incrementing strings
by ysth (Canon) on Mar 15, 2005 at 07:02 UTC
    s/// is the way to go, even without the period, since I don't think you want a sequence "madonna8", "madonna9", "madonnb0", "madonnb1", as string incrementing would do.