in reply to Second Time Replace Regex
How about something like:
my $file_name = ...; my $file; { open(my $fh, '<', $file_name) or die("Unable to open input file: $!\n"); local $/; $file = <$fh>; } my ($P) = $file =~ /A(.*?)B/ or die("Unable to find 'P'\n"); $file =~ s/(C.*?)\Q$P\E/$1Q/g; { open(my $fh, '>', $file_name) or die("Unable to open output file: $!\n"); print $fh $file; }
Update: Added \Q...\E.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Second Time Replace Regex
by JediWizard (Deacon) on Dec 02, 2005 at 22:37 UTC | |
by ikegami (Patriarch) on Dec 02, 2005 at 22:40 UTC |
In Section
Seekers of Perl Wisdom