in reply to Re: incremental substitution w/ regexp only?
in thread incremental substitution w/ regexp only?

ikegami! Why that lump of coal? The OPer said he'd been good all year!

>perl -wMstrict -le "my $test = 'abc1 abc1 abc1 abc1 abc1'; $test =~ s/1/++$1/eg; print $test; " Modification of a read-only value attempted at -e line 1.
Something like this works better:
>perl -wMstrict -le "my $addend = 0; my $test = 'abc1 abc1 abc1 abc1 abc1'; $test =~ s/(1)/$addend++ + $1/eg; print $test; " abc1 abc2 abc3 abc4 abc5

Replies are listed 'Best First'.
Re^3: incremental substitution w/ regexp only?
by ikegami (Patriarch) on Dec 25, 2008 at 14:32 UTC
    That's not the code I posted. You changed $i (9th letter) to $1 (one). My code works fine.
    >perl -le"$_='abc1 abc2 abc3 abc4 abc5'; s/1/++$i/eg; print" abc1 abc2 abc3 abc4 abc5
      Aha – a Christmas cracker!

      Update: Too late, I realized my reply should've been "'$i see!', said the blind man".