We help IT Professionals succeed at work.
Get Started

Output and page creation from html pages and a template...PERL/would mind making it in javascript

Caiapfas asked
Last Modified: 2011-09-20
Ok, This perl script scans a directory looking for <!-- balbal, yad yad --> on the first line of every .htm file and then looks at a template and matches the <!-- balbal, yad yad -->'s and inserts links.. Then displays the totals for each <!-- balbal, yad yad --> by displaying the blabla : 1000

What i would like to do with it now is make it display the GRAND total of all the links, and how many it had to dump due to no home. after the display of how many in each catogory.
Example :

Total Links : 2474
Total lost/dumped : 123

and with the dumps, dump them into a text file in link format <a href="http://www.mysite.com/whatever/me.htm>example</a>
for easy cut and paste

and the last option to perfect this script,
I need a prompt that ask ( Do you want to use the template to make a page for (E)each catogroy or (M)one main index page? )
The idea, main catorory is the way its designed now, with the one page..with all the links on it.
but, catogory would be a page for each <!-- new catorgory, blabla --> ...so in effect it takes the template and inserts the link after <!-- START --> instead of matching... reason i would like this option is in the times i have 1000+ links the htm file is pushing 1mb.. so i'd like a page for each catogory..may it be venues/artist..etc

------ add.pl ---------


# $dir is the directory with the html pages (e.g. c:\\concert)
# $wdir is a path the path to be inserted in the URLs (e.g. /whatever/concerts)
# $indextpl is the index template file (e.g. C:\\test\\index.tpl)
# $indexhtm is the final index file (e.g. c:\\test\\index.htm)
# The script has been tested under unix. For WIn32 you might need to change the slashes in paths from / to \\, and also the perl path in the first
# line.

$indextpl = "C:\\web\\ticketstogo.com\\venues\\states\\tempindex.htm";
$indexhtm = "C:\\web\\ticketstogo.com\\venues\\states\\aindex.htm";

# read venue files
opendir(DH, $dir) or die "Can't open $dir for reading: $!";
while(defined($file=readdir(DH))) {
  next unless $file =~ /\.htm$/i;
  open(FILE, "<$dir/$file") or die "Can't open $file for reading: $!";
 # $ven{$1}{$2} = "$wdir/$file" if <FILE> =~ /^\<\!-- (.*), (.*) --\>$/;
    $ven{lc($1)}{$2} = "$wdir/$file" if <FILE> =~ /^\<\!-- (.*), (.*) --\>$/;

# process template
open(IDXIN, "<$indextpl") or die "Can't open $indextpl for reading: $!";
open(IDXOUT, ">$indexhtm") or die "Can't open $indexhtm for writing: $!";
while(<IDXIN>) {
  if(/^\<\!-- (.*) --\>$/) {
    my @vkeys = sort keys %{$ven{lc($1)}};
    print "$1: " . @vkeys . "\n";
    print IDXOUT map {"<A href=\"$ven{lc($1)}{$_}\">$_ event tickets</A><BR>\n"} @vkeys;
  } else {
    print IDXOUT;
Watch Question
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE