in reply to Execution hangs on File::Find
It sounds like execution just takes a while, probably because there are a lot of files on your mapped drive, and access is slower than a local drive (I'm guessing this is a network directory?). Maybe you can log progress (eg: report on current position every 100 file?) to show that something is still happening
One obvious optimization is to only traverse the tree once. And since this would make the "wanted" function a little more complex, it's easier to read if you don't define it directly in the call to find:
I've also put the test on the file name first, it's a guess that it might be a little faster, because the name is already in memory and doesn't require drive/network access. And I'm not sure but it kind of looks like you have global variables, so I've shown you how you can have variables shared between functions without making them available everywhere.{ my $lastepch = time; my @files; my @todel; my $counter; sub wanted { $logger->info("Reached $File::Find::name") if ($counter++ % 100) = += 0; push @files,$File::Find::name if (/\.*$/ and -f $File::Find::name +and stat($File::Find::name)->mtime > $lastepoch); push @todel,$File::Find::name if (-d $File::Find::name); }, $indir +; } sub Get_FileList { @files = (); @todel = (); find (\&wanted, $_[0]); $lastepch = time; ... return (\@files, \@todel); } } my ($files, $todel) = Get_FileList($indir);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Execution hangs on File::Find
by colox (Sexton) on Dec 04, 2017 at 11:52 UTC | |
by Eily (Monsignor) on Dec 04, 2017 at 13:24 UTC |