in reply to incremental substitution w/ regexp only?

$test =~ s/1/++$i/eg;

Replies are listed 'Best First'.
Re^2: incremental substitution w/ regexp only?
by AnomalousMonk (Archbishop) on Dec 25, 2008 at 14:31 UTC
    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
      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".