Solved

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

Posted on 2007-11-20
1
158 Views
Last Modified: 2011-10-03
This is in reference to
http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_22949794.html

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.

Thanks
0
Comment
Question by:kailee
1 Comment
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
ID: 20320566

#!/usr/bin/perl
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$/;
      $value=$attr->{href};
}
chdir("/home2/mdc/public_html/mrd/final/news/");
 
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

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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