File::Find munging order of dirs/files

[email protected] ("Mark J. Reed") Thu, 5 Oct 2006 14:29:09 -0400
Newsgroups perl.cpan.discuss
Message-ID <[email protected]>
OK, a friend is trying to process directories and then files. They
have a preprocess routine that sorts thus, but the files are still
getting processed first.  Investigation revealed that the inner loop
calls wanted() on files immediately while pushing the dirs onto a
stack for later processing (File/Find.pm v1.10, starting at line 907):

          if (-d _) {
                        --$subcount;
                        $FN =~ s/\.dir\z//i if $Is_VMS;
                        # HACK: replace push to preserve dir traversal order
                        #push @Stack,[$CdLvl,$dir_name,$FN,$sub_nlink];
                        splice @Stack, $stack_top, 0,
                                 [$CdLvl,$dir_name,$FN,$sub_nlink];
                    }
                    else {
                        $name = $dir_pref . $FN; # $File::Find::name
                        $_= ($no_chdir ? $name : $FN); # $_
                        { $wanted_callback->() }; # protect against wild "next"
                    }

So, uhm, anyone know why?  I see lots of "HACK:" comments indicating
some history here...

-- 
Mark J. Reed <[email protected]>