in reply to Trying to substitute a variable with another variable in a string but not working
my $cell_name = "xyz"; while (<DATA>) { if (/STARTING_PATTERN\s+(.*)/) { $string = $_; $sub = quotemeta $1; $string =~ s/$sub/$cell_name/; print $string; } } __DATA__ STARTING_PATTERN RRR
Output:
STARTING_PATTERN xyz
Perhaps your input isn't as simple as RRR. If it contains regex metacharacters, use quotemeta, as shown.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Trying to substitute a variable with another variable in a string but not working
by kaushik9918 (Sexton) on Feb 24, 2015 at 16:06 UTC |