4 points:
===
(1) I'm not sure you've structured your code correctly.
Normally you don't use File::Find recursively.
The typical use is:
use File::Find;
find(\&wanted, @directories_to_search);
sub wanted { ... }
ie you make 1 single call to find().
Then find() calls the provided callback function wanted() for each file and directory it finds as it searches the provided directories.
In your case you might have:
use File::Find;
find( { wanted => \&_process_files, no_chdir => 1 }, @directories_to_
+search);
sub _process_files
{
my $file = $File::Find::name;
# .json file
if (-f $file and ($file =~ /\.json\Z/)) {
_process_json($file);
}
}
===
(2) Is your regexp correct?
If you're interested in files with an extension of ".json", then it should look like this:
$file =~ /\.json$/i
===
(3) As everyone has said, in this case the function call time is tiny compared with the disk I/O time.
===
(4) What I normally do
if processing the files will take significantly more time than finding the files is this:
- find all the files of interest and store them in an array
- process each file in the array
The advantage of this is in step 2 you can provide the user with feedback like:
"Currently processing file 123 of 12345 files. Estimated time to finish is xxxx".
To provide an accurate ETA,
if the time to process a file is proportional to the file's size, you would need to save the size of each individual file as it is found in step 1.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.