Next The Identity Function 33

Directory Computing

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


Next Copyright © 2001 M. J. Dominus