abulafia has asked for the wisdom of the Perl Monks concerning the following question:
This seems like it should be straightforward, but I'm clearly missing something.I'm trying to iterate over lists of substituion REs, and the substitutions aren't substituting.
I have something like (heavily simplified):
The 'first' regex, instead of printing 'first: big mess' prints 'first: $1 $3'.%regexes = (first => ['(\w+) (\w+) (\w+)', '$1 $3'], second => ['and so on', 'and on'] ); my $string = "big hairy mess"; foreach my $re (keys %regexes) { $string =~ s/$regexes{$re}[0]/$regexes{$re}[1]/i; print "$re: $string\n"; }
I've tried adding the /e switch, which didn't help, and wrapping the backreferences in (?{}) blocks, which didn't help.
I'm sure I'm missing something stupid, but can't figure out what that might be. Hints?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Storing substitution patterns
by Abigail-II (Bishop) on Feb 11, 2004 at 15:07 UTC | |
by duff (Parson) on Feb 11, 2004 at 15:22 UTC | |
by abulafia (Sexton) on Feb 11, 2004 at 16:22 UTC | |
|
Re: Storing substitution patterns
by Fletch (Bishop) on Feb 11, 2004 at 15:07 UTC | |
|
Re: Storing substitution patterns
by duff (Parson) on Feb 11, 2004 at 14:57 UTC | |
|
Re: Storing substitution patterns
by Hena (Friar) on Feb 11, 2004 at 14:49 UTC | |
by duff (Parson) on Feb 11, 2004 at 14:59 UTC |