kaushik9918 has asked for the wisdom of the Perl Monks concerning the following question:
Hi I have tried the following code to conditionally substitute a variable string with another variable string, but its not working. Can anyone please let me know why or point me to another similar solution already discussed before? Thanks
my $cell_name ="xyz"; while (<FILE>){ if($_ =~ /STARTING_PATTERN\s+(.*)/){ $string=$_; $sub=$1; $string =~ s/$sub/$cell_name/ ; } } close FILE;
If my <FILE> contains the line with the string "STARTING_PATTERN RRR" it should be replaced by "STARTING_PATTERN xyz". Please remember $cell_name is not always "xyz" - its a variable, I have just used "xyz" for illustration purpose here.
|
|---|