luc.bouge has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks
I have tried the following replacement script, which does not work.
However, it works fine with an additional escaping backslash before the left brace: s/(a)(b)/$1\{$2}/g;. I suspect that $1{$2} is recognized as addressing an associative array, but I could not find any mention in the documentation about such an expansion in the substitution part of a RE. Could somebody tell me? Regards, Luc.$ more replace.pl #!/usr/bin/perl -w -pi.orig s/(a)(b)/$1{$2}/g; $ more test.txt ab $ ./replace.pl test.txt Use of uninitialized value within %1 in substitution iterator at ./rep +lace.pl line 3, <> line 1. $ more test.txt (an empty line)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Brace in the replacement part of a regular expression substitution
by haukex (Archbishop) on Oct 22, 2018 at 07:32 UTC | |
|
Re: Brace in the replacement part of a regular expression substitution
by kcott (Archbishop) on Oct 22, 2018 at 07:52 UTC | |
|
Re: Brace in the replacement part of a regular expression substitution
by AnomalousMonk (Archbishop) on Oct 22, 2018 at 20:16 UTC |