Gossamer Forum
Home : General : Perl Programming :

Substitution Question

Quote Reply
Substitution Question
I've got a bit of code that takes mailing addresses and compares them against the US Postal Service Webpage.

I need help getting Perl to Interpret or Ignore certain parts of the address.


(user enters)
$address = "1313 Mockingbird Lane";

(postal service returns)
$post_address = "1313 MOCKINGBIRD LN";

if ($address ne $post_address) {
print "ERROR";

I get an error because the two don't match on "LANE vs. LN"

(I've taken care of the case-sensitivity by converting $address to uppercase.)

What I need help on is someway to tell Perl to accept either LANE or LN; DRIVE or DR; E. or EAST, etc. (it's the abbreviations that are causing me grief)

Any suggestions?

Right now I compare Address, City, State and Zipcode separately.
Quote Reply
Re: [Watts] Substitution Question In reply to
Have you tried using patterns such as "(lane|ln)" and "(east|E)"?

Or, you can do something like:

my $address = '1234 North Main Street';

my $abbr = {
lane => "ln",
north => "n"

foreach my $sub (keys %$abbr) {
$address =~ s,$sub,$abbr->{lc($sub)},egi;

This way you can force both address to have the same ordinal and road naming.

Limecat is not pleased.