in reply to Efficient way to replace a set of values with another set of values
Maybe a little something like this?
my $string = q{ 1. This is just a sample. 2. This is to check 3. How a set of values 4. can be replaced by another 5. set of values and that too 6. in the most efficient way. }; my %replacements = ( '1.' => 'a.', '2.' => 'b.', '3.' => 'c.', '4.' => 'd.', '5.' => 'e.', '6.' => 'f.', ); my $regexp = join '|', map quotemeta, keys %replacements; $string =~ s/($regexp)/$replacements{$1}/g; print $string;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Efficient way to replace a set of values with another set of values
by ColonelPanic (Friar) on Nov 23, 2012 at 10:19 UTC | |
by tobyink (Canon) on Nov 23, 2012 at 10:50 UTC | |
by ColonelPanic (Friar) on Nov 23, 2012 at 11:04 UTC |