On 12/16/2011 03:23 PM, Chris Stinemetz wrote:
Hello Melvin,

Give this a try. I used the advice Jim gave and this is what I came up
with. It seems to do what you are asking for.

#!/usr/bin/perl
use warnings;
use strict;

my $inFile = "input.txt";
my $outFile = "output.txt";

open my $fin, '<', $inFile or die "ERROR opening $inFile: $!";
open my $out, '>', $outFile or die "ERROR opening $outFile: $!";

while( my $line =<$fin>  ) {
   $line =~ s/baby/bigboy/g;
   print $out $line;
}

or even simpler and much faster:

use File::Slurp qw( edit_file ) ;

        edit_file { s/baby/bigboy/g } 'file.txt' ;

it will edit the file in place safely.

uri


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to