Monks,

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?


In reply to find loses $found in find by Dave05

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.