Next The Identity Function 31

Directory Searching

        sub print_files {
          my ($dir) = @_;
          if (-d $dir) { 
            print $dir, "\n";
            opendir my $dh, $dir or return;
            while (my $file = readdir $dh) {
              next if $file eq '.' || $file eq '..';
              print_files("$dir/$file");
            }
          } else {
            print $dir, "\n";
          }
        }


Next Copyright © 2001 M. J. Dominus