| Next | The Identity Function | 33 | 
What we can't do yet is something like the Unix du command
This accumulates a per-directory total
        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 |