need a recursion? well then do it:
#!/usr/bin/env perl
use warnings;
use strict;
my $curUrl = "http://localhost:8080";
my $tarUrl = "http://localhost";
my @buf;
my ($line, $f);
sub diveinto {
print "dive into: $_[0]\n";
opendir DIR, $_[0] or die "Could not open directory";
my @files = readdir DIR;
closedir DIR;
foreach $f (@files) {
if ($f =~ /\.{1,2}/) {next }
print "processing: $f\n";
if ( -d "$_[0]/$f" ) { diveinto ("$_[0]/$f") }
else {
open FILE, "<". "$_[0]/$f" or die "Could not open file --
+$_[0]/$f";
@buf = <FILE>;
close FILE;
open W, ">" . "$_[0]/$f" or die "cunt open for r/w -- $_[0
+]/$f";
foreach $line (@buf) {
$line =~ s/$curUrl/$tarUrl/g and print "Yes";
print W $line;
}
close W;
}
}
}
diveinto $ARGV[0];
* I leave debug 'print'-s as is to help you understand what it does. It can be shrinked twice in size.
* If it is a directory, we just call ourselves recursively
* The original loop where you trying to replace string need to write result of s///;