# comments refer to benchmark tests using ~/Documents/ and ~/etext/ dirs sub want_file { my $filename = shift; if ( $check_type && -T $filename ) { # 15061 filenames in 0.692 sec return 1; } elsif ( $check_extensions ) { # 8857 filenames in . 0.794 sec with # --extensions=txt,pl,html,htm if ( ( grep { $filename =~ m(\.$_$) } @file_extensions ) && -e $filename) { return 1; } } else { # this test finds 5066 files in ~/Documents and ~/etext # in 0.218 sec if ( $filename =~ m(\.txt$) && -e $filename ) { return 1; } } return 0; } sub recurse_dir { my $dirname = shift; local *D; opendir D, $dirname; my $fname; while ( $fname = readdir D ) { my $name = $dirname . "/" . $fname; if ( -d $name ) { # don't recurse on . or .. or dotfiles generally if ( $fname !~ /^\./ ) { print "$name is a dir\n" if $debug >= 3; &recurse_dir( $name ); } } elsif ( &want_file( $name ) ) { print "$name is a text file\n" if $debug >= 3; push @filenames, $name; } else { print "skipping $name\n" if $debug >= 3; } if ( $preload_paras and ((rand 100) < 1) ) { print "preload mode so printing something while still gathering filenames (" . (scalar @filenames) . " read so far)\n" if $debug; if ( scalar @filenames ) { &add_paras; &slow_print( int rand scalar @paras ); } else { print "...but there are no usable files yet\n" if $debug; } } } closedir D; }