At 06:05 AM 11/19/01 -0800, Jean-Paul Miéville wrote: >I don't understand the difference between these two functions: find and >finddepth in module File::Find. I don't understand the explanation in >perldoc. My experience shows that finddepth is about 50% faster than find. >Why ?
A depth-first search means that all subdirectories are visited before their parent directories. There are advantages to this ordering for certain tasks. Given this hierarchy: $ ls -lR top top: total 4 drwxrwxr-x 3 peter peter 4096 Nov 19 10:50 second -rw-rw-r-- 1 peter peter 0 Nov 19 10:50 topfile top/second: total 4 -rw-rw-r-- 1 peter peter 0 Nov 19 10:50 secondfile drwxrwxr-x 2 peter peter 4096 Nov 19 10:50 third top/second/third: total 0 -rw-rw-r-- 1 peter peter 0 Nov 19 10:50 thirdfile Then here is the difference between the orderings: notice that while the subdirectories are processed before their parents with finddepth, the ordinary files are processed before the subdirectories. It's never been a problem for me but somehow it seems wrong *shrug*: $ perl -MFile::Find -le 'find(sub {print $File::Find::name}, "top")' top top/topfile top/second top/second/secondfile top/second/third top/second/third/thirdfile $ perl -MFile::Find -le 'finddepth(sub {print $File::Find::name}, "top")' top/topfile top/second/secondfile top/second/third/thirdfile top/second/third top/second top I don't honestly know why finddepth should be faster. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]