Next The Identity Function 32

Directory Searching

        sub walk_tree {
          my ($dir, $filefunc, $dirfunc) = @_;
          if (-d $dir) {
            $dirfunc->($dir);
            opendir my $dh, $dir or return;
            while (my $file = readdir $dh) {
              next if $file eq '.' || $file eq '..';
              walk_tree("$dir/$file", $filefunc, $dirfunc);
            }
          } else {
            $filefunc->($dir);
          }
        }
        walk_tree($DIR, sub {}, sub { print $_[0] });
        my @FILES;
        walk_tree($DIR, sub {push @FILES, $_[0]}, sub {});


Next Copyright © 2001 M. J. Dominus