I'd like to thank everyone who offered their input for my problem, I got everything working. And no, this wasn't for a class, it was a "busy-work" assignment for work that got handed down, I wanted to use PERL to both save time, and learn something new.
Here is my completed code:
use strict;
use warnings;
use diagnostics;
use File::Find;
use HTML::HeadParser;
my $parser = new HTML::HeadParser;
my @data;
my $path = '/base/path';
&main;
sub main
{
find(\&html_files, $path);
open OUT, "+>filelist.html" || die "Can not write file";
print OUT
'<html><head><title>File List</title></head><body><center>'
+, "\n",
'<table border="1" cellpadding="5" cellspacing="0">', "\n";
foreach my $file(sort @data)
{
my $htmlPage = &fileRead("<$file");
$parser->parse($htmlPage);
my $pageTitle = $parser->header('Title');
if ($pageTitle eq "")
{
$pageTitle = ' ';
}
print OUT '<tr><td>', "\L$file\E", '</td><td>', $pageTitle
+, '</td></tr>', "\n";
}
print OUT '</table></body></html>';
close OUT;
}
sub html_files
{
push @data, $File::Find::name if /\.s?html?$/;
push @data, $File::Find::name if /\.s?HTML?$/;
push @data, $File::Find::name if /\.s?htm?$/;
push @data, $File::Find::name if /\.s?HTM?$/;
}
sub fileRead
{
my ($file) = @_;
my $dataIn = undef;
open IN, $file || die "Can not open $file";
while (<IN>)
{
my $temp = $_;
$dataIn = $dataIn.$temp;
}
close IN;
return $dataIn;
}
Arashi
I'm sure Edison turned himself a lot of colors before he invented the lightbulb. - H.S.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.