najiz has asked for the wisdom of the Perl Monks concerning the following question:
I have the following code to replace text in one file. How do I modify this code to replace text in multiple files with same extension.
*********************************#!/usr/bin/perl $file = "new.txt"; open (IN,$file) || die "could not open ".Sfile." for read"; @lines=<IN>; close IN; open (OUT,">", $file) || die "can not open file ".$file." for write"; foreach $line (@lines) { $line =~ s/Hello/goodby/ig; print OUT $line; } close OUT;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Replace strings in multiple files
by zentara (Archbishop) on Nov 13, 2012 at 13:18 UTC | |
Re: Replace strings in multiple files
by space_monk (Chaplain) on Nov 13, 2012 at 13:39 UTC | |
by Tanktalus (Canon) on Nov 13, 2012 at 16:16 UTC | |
by afoken (Chancellor) on Nov 13, 2012 at 17:10 UTC | |
by Tanktalus (Canon) on Nov 13, 2012 at 20:33 UTC | |
by space_monk (Chaplain) on Nov 13, 2012 at 16:16 UTC | |
Re: Replace strings in multiple files
by Anonymous Monk on Nov 13, 2012 at 13:51 UTC |
Back to
Seekers of Perl Wisdom