On 04/26/00, "[EMAIL PROTECTED]" wrote:
> Suppose I have a file sub.txt that looks like this
>
> old1 new1
> old2 new2
> I have a document in which I need to replace all occurences of old1 with
> new1, etc. can anyone help me with a possible script? Can my script work
> with a word document? Thanks.
Something like this?
#Suppose files are opened
my @arr;
#Read in old and new definitions
while (<OLDNEW>) {
chomp;
my ($old, $new) = split;
# Do we want to delimit on word boundaries?
# If not, leave out '\b's
my $pttrn = qr/\b${old}\b/;
push @arr, [ $pttrn, $new ];
}
#Read the file we want to change
while (<CHANGEFILE>) {
for my $ref (@arr) {
s/$ref->[0]/$ref->[1]/g;
}
# Print the output?
print OUTPUT;
}
HTH,
Douglas Wilson
---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
[EMAIL PROTECTED]
For non-automated Mailing List support, send email to
[EMAIL PROTECTED]