#
# This software is Copyright 2005 by Elsevier Inc.  You may use it
# under the terms of the license at http://perl.plover.com/hop/LICENSE.txt .
#



###
### dir_walk_filter_recursive
###

## Chapter 4 section 6.1

# recursive version
sub dir_walk_filter {
  my ($top, $code) = @_;
  
  my @result = $code->($top);
  
  if (-d $top) {
    my $file;
    unless (opendir my($DIR), $top) {
      warn "Couldn't open directory $top: $!; skipping.\n";
      return;
    }
    while ($file = readdir $DIR) {
      next if $file eq '.' || $file eq '..';
      push @result, dir_walk_filter("$top/$file", $code);
    }
  }
  return @result;
}
