Dave05 has asked for the wisdom of the Perl Monks concerning the following question:
I came across this problem while using File::Find to find files modified after a certain time. When a file is found, I call a subroutine that itself uses File::Find to find a set of related files that need to be updated. Except it doesn't work. The first 'find' catches the first file, calls the sub, which runs OK, but then the whole thing comes to a stop. No error, just a normal end of program. My question is, why does the first 'find' not continue?
Here's an example script that illustrates the problem:
#!/usr/bin/perl use warnings; use strict; use File::Find (); # See the Cookbook p.324 to sub find (&@) { &File::Find::find } # call find like grep or map my $start = 'd:/temp'; find { find_again($_) if (-d && !/^\./)} $start; sub find_again { my $found = $_; print "First find found: $found\n"; print "Second find found dirs:\n"; find { print "$_\n" if (-d && !/^\./)} $found; } __END__ Directories are: d:/temp/one/a /b /c /two/d /e /f /three/g /h /i OUTPUT: First find found: two Second find found dirs: d e f d e f one a b c three g h i
Two things are going on here that I don't understand. First, why is find_again printing out all these directories? It was only ever called once, with /two as the starting directory. Second, why is find_again only called once? It should (well, what I intended) be called three times, on /one, /two and /three.
I thought the problem might be find changing the current directory, so I cached it at the start of find_again and chdir'd back at the end, but that made no difference.
Can the Monks enlighten me?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: find loses $found in find
by demerphq (Chancellor) on Sep 13, 2002 at 12:33 UTC | |
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 | |
|
Re: find loses $found in find
by bronto (Priest) on Sep 13, 2002 at 12:11 UTC | |
|
Re: find loses $found in find
by PodMaster (Abbot) on Sep 13, 2002 at 11:19 UTC | |
by Dave05 (Beadle) on Sep 13, 2002 at 11:34 UTC |