|P is for Practical|
Re: Efficiency: Recursive functions while de-subbing my programby zork42 (Monk)
|on Jul 13, 2013 at 10:35 UTC||Need Help??|
(1) I'm not sure you've structured your code correctly.
Normally you don't use File::Find recursively.
The typical use is:
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:
(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:
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.