How Do I Retrieve Unit from Geo::StreetAddress::US Perl Module, Possible module modification required?

I am tasked with parsing a good deal of addresses (first batch is 47,000) into individual components so that they can later be imported into an SQL database.  I started with a CPAN search and found a few promising Perl modules.  Of those Geo::StreetAddress::US appeared to be the best fit.  Of the ones I tested it was the most accurate and also the fastest.  I also played with Lingua::EN::AddressParse but it failed to properly parse some addresses and took about 3 times as long as Geo::StreetAddress::US.

My problem is that I can return all of the data I need except for the Unit (apt, bldg, etc).  I don't think this was a priority for the module's author as it was being used to find lat/long for .  I've attached the bit of code I am using for testing and it returns everything I need except the unit.  Am I making an error in my code or will I need to edit the module to make it do what I want?  Or am I just plain missing something?

I've also attached a copy of the module, though it is also available from  My Perl is beginner level at best and I'm having trouble following the flow of all the hashes and any edits I've made haven't made any difference.

Thanks in advance,

use Geo::StreetAddress::US;
$address = Geo::StreetAddress::US->parse_location( "1492 N Columbus BLVD APT 4,PORTLAND,OR,97203" );
print "number: " . $address->{'number'} . "\n";
print "prefix:  " . $address->{'prefix'} . "\n";
print "street:  " . $address->{'street'} . "\n";
print "type:  " . $address->{'type'} . "\n";
print "suffix:  " . $address->{'suffix'} . "\n";
print "city:  " . $address->{'city'} . "\n";
print "state: " . $address->{'state'} . "\n";
print "zip: " . $address->{'zip'} . "\n";
print "unit: " . $address->{'unit'} . "\n";

Open in new window
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The regex matches the unit, but doesn't save it.  You can make a change to the module code so it saves the unit:
On line 683-701, there is a definition of the hash %Addr_Match, with line 700 having the definition for unit.
If you change line 700 to this, you should get the unit:

unit    => qr/((?:(?:su?i?te|p\W*[om]\W*b(?:ox)?|dept|apt|ro*m|fl|apt|unit|box)\W+|#\W*)[\w-]+)(?{$_{unit} = $^N})/i,

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
telwestAuthor Commented:
Thank you.  That worked beautifully.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.