nemesdani has asked for the wisdom of the Perl Monks concerning the following question:
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 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File::find hack
by JavaFan (Canon) on Feb 25, 2012 at 11:45 UTC | |
by nemesdani (Friar) on Feb 25, 2012 at 12:03 UTC | |
by oko1 (Deacon) on Feb 25, 2012 at 14:04 UTC | |
|
Re: File::find hack
by oko1 (Deacon) on Feb 25, 2012 at 16:55 UTC | |
by nemesdani (Friar) on Feb 25, 2012 at 17:46 UTC | |
|
Re: File::find hack
by Marshall (Canon) on Feb 26, 2012 at 00:07 UTC |