In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Markus Treinen) writes: >Hi, >I have the following case: > >----- >my $reg_exp = qr/^ONE\.(\d{6})\.THREE$/; >my $replace_with = "FOUR.$1.FIVE"; > >my $example_file = "ONE.123456.THREE"; >$example_file = s/$reg_exp/$replace_with/; >----- > >In words, I want to reuse substrings from the matched string in the >replacement string. Both regexp and replacement must be in variables >defined BEFORE the actual substitution (user-configurable via config file). >The above example obviously doesn't work, because $1 isn't defined when >initializing $replace_with.
Then don't interpolate it beforehand. (Didn't you get a warning about "use of uninitialized value"?) my $reg_exp = qr/^ONE\.(\d{6})\.THREE$/; my $replace_with = 'FOUR.$1.FIVE'; my $example_file = "ONE.123456.THREE"; $example_file = s/$reg_exp/qq{"$replace_with"}/ee; -- Peter Scott http://www.perldebugged.com/ *** NEW *** http://www.perlmedic.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>