PERL BEGINNERS 3 RE HOW TO REPLACE A TEXT IN A FILE
Date: Tue, 5 Aug 2003 13:22:38 -0400 (EDT)

Subject: Re: How to replace a text in a file
From: japhy@no-spam (Jeff 'Japhy' Pinyan)

On Aug 5, Vinay Thombre said:

>I am novice to Perl and learning very basic things. I want to replace a text >in a file with new text. I want to do it programatically. How can I do that?

I hope you've got a good book or two, such as "Learning Perl" (the llama book) published by O'Reilly.

The basic setup you'll want to use is this:

open INPUT, "< in.txt" or die "can't read in.txt: $!";
open OUTPUT, "> out.txt" or die "can't write out.txt: $!";
while (my $line = <INPUT>) {
# do something to $line print OUTPUT $line;
}
close OUTPUT;
close INPUT;

-- Jeff "japhy" Pinyan japhy@no-spam http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]