FAQ
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

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 2 | next ›
Discussion Overview
groupbeginners @
categoriesperl
postedFeb 26, '09 at 1:02a
activeFeb 26, '09 at 2:05a
posts2
users2
websiteperl.org

2 users in discussion

Jim Gibson: 1 post Lemba: 1 post

People

Translate

site design / logo © 2022 Grokbase