#!/usr/local/bin/perl
if($#ARGV < 0) { @ARGV = ('res-final3.html'); }
foreach $file (@ARGV) {
@lv = split(/\n/,`cat $file`);
$title = '';
foreach $l (@lv) {
   if($l =~ /<tr><td>(\d+)<td>http:(.*)/) {
	$id = $1;
   }
   elsif($l =~ /<tr><td>(\d+)<td>(.*)/) {
	$id = $1;
	$title = $2;
   } 
   elsif($l =~ /<td><a href=\"([^\"]+)/) {
	$url = $1;
   }
   elsif($l =~ /([^<].*)<\/a>/) {
	&add_link();
   }
   elsif($l =~ /<\/a>/) {
	&add_link();
   }
   else {
	next;
   }
}
}
&write_url_table();
&write_title_table();

sub add_link {
if($url =~ /(.*):80/) { $url = $1; }
if($title eq '') { $title = 'No Title'; }
$urld{$url} = $title;
$titled{$title} = $url;   
#print "$id\n$url\n$title\n\n";
$title = '';
}

sub write_url_table {
print "\nURL Table\n---------------------------------\n";
foreach $url (sort(keys(%urld))) {
   $title = $urld{$url};
   print "$url\t$title\n";
}
}

sub write_title_table {
print "\nTitle Table\n---------------------------------\n";
foreach $title (sort(keys(%titled))) {
   $url = $titled{$title};
   print "$title\t$url\n";
}
}

