Gossamer Forum
Home : General : Perl Programming :

Global Search and Replace

Quote Reply
Global Search and Replace
Hello...

I have a script:

----------------------------------------------------------------------

#!/usr/bin/perl

print "Content-type: text/html\n\n";

$path='/web/disk1/virtual/domain.com/htdocs';

@files = File::Find::Rule->file
->in("/$path");

foreach $filename (@files)
{

open (IN, "$filename") || die $!;
open (OUT, ">new$filename") || die $!;

while ($_ = <IN> ) {

if ($_ =~ /and/) {
$_ =~ s/and/this_is_the_new_text/;
}

print OUT "$_ \n";

}

close (OUT);
close (IN);

rename("new$filename","$filename") || die $!;

}

----------------------------------------------------------------------

How can I get this to run through all of the subdirectories as well as just one...?

Thank you for all of your help...

Last edited by:

Traffic: Mar 10, 2004, 11:52 AM