$ perl -Mstrict -Mwarnings -E '
my $find = q{#define MYVERSION };
my $flen = length $find;
my @strings = (
q{#define MYVERSION 11},
q{#define MYVERSION 9},
q{#define MYVERSION 99}
);
for (@strings) {
say;
substr($_, $flen) = substr($_, $flen) + 1;
say;
}
'
#define MYVERSION 11
#define MYVERSION 12
#define MYVERSION 9
#define MYVERSION 10
#define MYVERSION 99
#define MYVERSION 100
Anyway, that's all fairly academic: I'm pretty sure I would have reached for something like s/^($find)(\d+)/$1.($2+1)/e in the first instance.
|