#!/usr/local/bin/perl # Author: Kevin P. Inscoe . # File: indexhtml.pl # Date of creation: March 9, 2004 # Version: 1.0 # Warranty: None expressed or implied. # License: The Open Software License. V1.1 http://www.opensource.org/licenses/osl.php # # OSI Certified Open Source Software. http://www.opensource.org/licenses/ # # Prerequisites: Perl 5.004 (minimum). require 5.004; # The purpose of this program is # # Scans the current directory for all *.html files and builds an index.html with links to the files using the # as the URL text. # #Turn off Perl buffering $| = 1; # Pragmas use strict; use diagnostics; require HTML::HeadParser; # Globals sub htmlindex_get_title; # Locals my ($dir, $file, $wfile, $title); my $cnt=0; # Main open (OUT, ">c:/temp/index.html") or die "Could not open index.html for output - $!"; print OUT "John's Index

John's Index

\n"; # Process each *.html file $dir = "c:/temp"; opendir(DIR, $dir) or die "Can't open $dir - $!"; while( defined ($file = readdir DIR) ) { if ( ( $file ne "index.html" ) && ( $file =~ '\.htm[l]$' ) ) { $wfile = $dir . "/" . $file; print "Parsing: $wfile\n"; $title = &htmlindex_get_title($wfile); print OUT "$title
\n"; $cnt++; } } closedir(DIR); print OUT "

$cnt files.\n\n"; print "\n$cnt files indexed.\n\n"; close(OUT); sub htmlindex_get_title { my ($file) = @_; my ($title, $tmp, @buf, $rec, $p); open (IN, "<$file") or die "Could not open $file for input - $!"; @buf=; close(IN); foreach $rec (@buf) { $p = HTML::HeadParser->new; $p->parse($rec); $tmp = $p->header('Title'); if (defined($tmp)) { $title = $tmp } } print " =$title\n"; return $title; }