#!/usr/local/bin/perl5 -w
use strict;

my $address_file = "firms.dat";
my $URL = "http://www.usps.gov/cgi-bin/zip4/zip4inq2";

my $PS1 = "\"Firm=";
my $PS2 = "\&Urbanization=\&Delivery+Address=";
my $PS3 = "\&City=Pittsburgh\&State=PA\&Zip+Code=\"";

open (INPUT, "<$address_file") || (die "Can't open address file");
 
# for each line in the address list 
while (my $firm = <INPUT>) {
    chomp $firm;
    my $xfirm = $firm;
    $xfirm =~ s/\s/\+/g;
    my $address=<INPUT>;
    chomp $address;
    $address =~ s/\s/\+/g;
    my $poststring = $PS1 . $xfirm . $PS2 . $address . $PS3;
    my @html_source = `echo $poststring | lynx -dump -post_data \"$URL\"`;
    print $firm, "\n", grep(/PITTSBURGH/,@html_source);
}

close(INPUT);

