in reply to Incremental replacement by regex
Gives:use strict; use warnings; my $str = "This example could be another example where the example is +the example I wanted"; my $i = 0; $str =~ s/example/'example_'.++$i/eg; print "$str\n";
At the end of the substitution statement, the 'e' executes the code and the 'g' repeats the substitution for the next occurrence of the string. The ++ is the prefix operator, so it is executed before the rest of the statement.This example_1 could be another example_2 where the example_3 is the e +xample_4 I wanted
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Incremental replacement by regex
by markdibley (Sexton) on Feb 21, 2011 at 13:43 UTC | |
by cdarke (Prior) on Feb 21, 2011 at 14:18 UTC |