On Fri, 25 Mar 2005 11:45:04 +0100, Detlef Lindenthal wrote:
>## Type alle the names and paths of the files within a folder tree:
>use File::Find;
>@ARGV = qw(.) unless @ARGV;
>find sub { print $File::Find::name, -d && '/', "\n" }, @ARGV;
You'd better replace that slash with a colon, on a Mac.
>Now again my question:
>Can someone add some lines, so I can do search-and-replace within each file?
You need a callback sub like this (anonymous) one:
use File::Find; use Cwd;
find sub {
if(-f and /\.pl$/ and open my $fh, $_) {
local($_, $.);
while(<$fh>) {
chomp;
print "$File::Find::name ($.): $_\n" if /foo/;
}
}
}, cwd;
BTW cwd() is just a way to get a platform independent definition of "."
which also produces a proper absolute file path.
--
Bart.