Laudetur, monks. My problem is: In a given tree of subdirs, on the lowest level there are files, on other levels there aren't. In every subdir on the lowest level I'd like to select a certain file (newest from a certain type) and not process the others.

Now I've written a script, using File::find, which uses last to skip checking other files once I found one, thus skipping to the next directory. I think there are more elegant and/or efficient ways to this, I don't like using last.

Please share your thoughts. Thank you.

use strict; use warnings; use File::Find; my $dir = "d:\\Teszt"; finddepth(\&gotcha, $dir); sub gotcha { if ($dir eq $File::Find::dir){ print "same dir, skipping\n"; last; } else {$dir = $File::Find::dir;} if (-f) {print "$File::Find::name\n"; &process_files_in_subdir() } } sub process_files_in_subdir { ; #whatever }

In reply to File::find hack by nemesdani

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.