in reply to Multiple substitute values
Please show us the code you have. A possible approach is:
use strict; my %repl = ( Jan => 'JOO', Fan => 'FOO', Janu => 'JOOU', ); my $search = join "|", map { qr-\b$_\b- } keys %repl; print "Search regular expression is >>$search<<\n"; my $string = "Jan said: I'm a real Fan of Janus. I call him Janu."; print "$string\n"; $string =~ s/($search)/$repl{$1}/ge; print "$string\n";
See perlre for further information on /g and /e.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Multiple substitute values
by johngg (Canon) on Sep 21, 2007 at 10:39 UTC | |
|
Re^2: Multiple substitute values
by ikegami (Patriarch) on Sep 21, 2007 at 13:16 UTC |