Hi All,
I'm trying to replace some text in file. Below is my script. It
basically makes a copy of line with changes. How can I replace pattern
in the uxix sed way?
use strict;
use warnings;
use Cwd;
use Win32;
use File::Path;
use File::Find;
use File::Basename;
@ARGV = Win32::GetCwd() unless @ARGV;
my @source;
find (\&findSource, $ARGV[0]);
foreach ( @source )
{
open SOURCE, "+<", $_ or die "Error: $!\n";
my @file = <SOURCE>;
seek SOURCE,0,0;
foreach my $file (@file)
{
if ( $file =~ /STARBUCKS.*RESTAURANT/i )
{
$file =~ s/RESTAURANT/CAFE/g;
print SOURCE $file;
}
}
close SOURCE;
}
Example of my original file:
STARBUCKS|RESTAURANT
JACK IN THE BOX|RESTAURANT
STARBUCKS|RESTAURANT
MC DONALDS|RESTAURANT
after replacement it should be like this:
STARBUCKS|CAFE
JACK IN THE BOX|RESTAURANT
STARBUCKS|CAFE
MC DONALDS|RESTAURANT
Thanks in advance,
Vladimir
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/