#! /usr/bin/perl -w

use strict;				# always use strict
use File::Find;				# does the recursion for you
use File::stat;				# object-oriented, better than stat()
use Template;				# from the CPAN Template Toolkit
use CGI qw /:standard/;			# to get parameters, CGI::Lite is also OK
use CGI::Carp;				# to die gracefully

$| = 1;					# flush all output
my %files;

sub wanted
{
 return unless -f; # only remember the statistics files
 $files{$File::Find::name} = stat $_;
}

print "Content-type: text/html\n\n";

my $query = new CGI;
my $dir = $query->param("dir");

if (defined $dir)
{
 find(\&wanted, $dir);			# or use CGI param() method to get directories to recurse

 my $vars = {
	     files => \%files,
	     octal => sub { return sprintf '%o', @_ },
	    };
 
 my $template = Template->new();
 
 $template->process(\*DATA, $vars)
  || die $template->error();
}
else					# feel free to make this fancier, with input forms etc.
{
 print <<EOHTML;
You must provide a directory with the 'dir' CGI parameter
EOHTML
}


# the template for the web page is here...
__DATA__
<html>
<head>
<title>Files found</title>

</head>
<body>
<h1>Files found</h1>

[% FOREACH file = files.keys %]
<p>
File [% file %]<br>
Size [% files.$file.size %] bytes<br>
Mode [% octal(files.$file.mode) %]<br>
[% END %]

</body>
</html>
