#!/usr/bin/perl

$dir_d = $ARGV[0];
$dir_n = $ARGV[1];

$fname = "$dir_d" . "_" . "$dir_n.html";
open FILE, "<$fname" or die "Error cant't open $fname\n";
@data = <FILE>;
close FILE;

$x = $data[25];
@data = (@data)[44..$#data-10];
$x =~ s/\D//g;
$x =~ s/^0*//g;

$city = shift @data;
$post = shift @data;
$tel  = shift @data;
print "$x\n";

foreach $line (@data) {
    chomp($line);
    if ($line =~ /\<TD NOWRAP\>.*\<\/TD\>/) {
	$line =~ s/<.*?>//g;
	push @parsed, $line;
    };
};

open FILE, ">parsed/$fname.parsed";

for ($i=0;$i<=$#parsed;$i+=3) {
    print FILE "$parsed[$i];$parsed[$i+1];$parsed[$i+2]\n";
};

close FILE;
