in reply to How to eval an array element in regex's substitution
First, \1, etc are regex patterns. You want $1, etc.
Secondly, you have some serious misconception about the replacement expression.
Without /e, it's a double-quoted string literal that evaluates to the replacement.
With /e, it's a Perl expression which evaluates to the replacement.
my $s = 'Hello [2][1]'; my @a = ('x','y','z'); $s =~ s/\[(\d{1,2})\]/$a[$1]/g; print $s;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to eval an array element in regex's substitution
by pysome (Scribe) on Oct 27, 2010 at 04:48 UTC | |
by ikegami (Patriarch) on Oct 27, 2010 at 06:48 UTC |
In Section
Seekers of Perl Wisdom