#!/usr/bin/perl -w
# -T can only be given on the command line (taint checking)
use strict; # homework by Eric Auer...
# task: use the perl find module to check all files in a
# directory tree for some property, and return a list...

use File::Find;
my %filelist; # whoa, a global var...

sub xprint {
#  print "" . $_[0] . ""; # redefine to no-op to avoid printing
                          # of the file list...
}

sub addhtml { # add to filelist if name ends in htm(l)
  my $who = $File::Find::name;
  if (-d $who) { print STDERR "Directory $who\n"; }
#  print "??? $who\n" if (!-f $who);
  if ((-f $who) && ($who =~ /[.]([sp])?htm(l)?$/)) {
    $filelist{$who} = 1;
  }
}

sub addascii { # add to filelist if ASCII test succeeds
  my $who = $File::Find::name;
  if (-d $who) { print STDERR "Directory $who\n"; }
  if ((-f $who) && (-T $who)) { $filelist{$who} = 1; }
}

sub collecthtmlfiles { # make a list of HTML files in path arg
  my $PFAD;
  $PFAD = $_[0]; # get the where...
  %filelist = ();
  my $count = 0;

  find(\&addhtml, $PFAD);

  print "HTML files found:\n";
  for my $thekey (sort keys %filelist) {
    &xprint("$thekey\n"); $count++;
    if ($thekey =~ /:/) {
      print STDERR "Illegal : in filename, skipping "
        . "further processing of\n<$thekey>\n";
      $filelist{$thekey} = undef;
    }
  };
  print "$count HTML files found.\n\n";
  return (join(":",keys %filelist));
}

return 1; # make require succeed

