How do I make a series of text links from a directory of html files

Posted on 2007-11-20
Last Modified: 2011-10-03
This is in reference to

I would like this script to also generate a list of the index pages used to generate the drop down list.  This text list will be layed out in a table, with each cell containing a linked number to its corresponding index##.htm page.  The table should be generated dynamically.

Also, I would like that the links in the drop down list somehow include the corresponding index##.htm into each of its generated links, so that I may use a javascript to 'grab' that info for other use.

Question by:kailee
1 Comment
LVL 39

Accepted Solution

Adam314 earned 500 total points
ID: 20320566


use HTML::Parser;

use CGI qw(:standard);

print header, start_html('title');

my  $p = HTML::Parser->new(

   api_version => 3,

   start_h => [\&start, "tagname, attr"],

   end_h   => [\&end,   "tagname, skipped_text"],


my $value;

sub start{

      my ($tag, $attr) = @_;

      $value=undef,return if $tag ne 'a';

      return unless $attr->{href} =~ /openingindex\.htm$/;




my %texts;

sub end{

    my ($tag, $text) = @_;

    return if $tag ne 'a';

    return unless $value;

    $text =~ s/^\s*(.*?)\s*/$1/;

    $texts{$text}->[0] = $value;

    push @{$texts{$text}}, $FileName;


my $FileName;

$p->parse_file($FileName) foreach $FileName (<index??.htm>);

#To print a drop-down list:

print "<option value=\"$texts{$_}->[0]\">$_</option>\n" foreach (sort keys %texts);

#To print a table:

print "<tr><td>$_->[0]</td><td>$_->[1]</td></tr>\n" foreach (map {[$_, join(" ", @{$texts{$_}}[1..$#{$texts{$_}}] )]} keys %texts);

Open in new window


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now