in reply to find loses $found in find
The way to deal with this is to use something like a breadth-first-traversal pattern. Ie, when you find a file that will cause the files in some other directory to change then push that file onto a list. Find all the files that need such an action _first_ then do the updating afterwards. Something like so: (this says that if we find a file in the first find then we will delete all similarly named files in a different dir)
This is fairly idomatic perl code (sorry) but hopefully you get the idea.# untested example code that could cause all of your .pl files to be + deleted! my @fix; find {no_chdir=>1, wanted=>sub{ -f && m/\.pl$/ && push @fix,[File::Spec->splitpat +h($_)];} },@paths; foreach my $fix (@fix) { find { no_chdir=>1, wanted=>sub{ -f && (File::Spec->splitpath($_))[2] eq $fix->[2] && +unlink $_ } },do{ (my $x=$fix->[0].$fix->[1]) =~s/foo/bar/g; $x}; }
--- demerphq
my friends call me, usually because I'm late....
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: find loses $found in find
by Dave05 (Beadle) on Sep 13, 2002 at 13:31 UTC | |
by broquaint (Abbot) on Sep 13, 2002 at 15:53 UTC | |
by demerphq (Chancellor) on Sep 13, 2002 at 17:54 UTC | |
by demerphq (Chancellor) on Sep 13, 2002 at 14:52 UTC |