The Lucid Developer

Thursday, May 01, 2008

Breaking up an Address (Perl)

con·vo·lut·ed Pronunciation Key - Pronunciation[kon-vuh-loo-tid]
–adjective
1.twisted; coiled.
2.complicated; intricately involved: a convoluted way of describing a simple device.


Still working on this API. For some strange reason they require that all address be submitted to them in parts. So for example 164 N Cherry Lane would have to be submitted to them as:
Number: 164
Direction: N
Street: Cherry
Type: Ln

Other then the reasoning behind this boggles my mind, I pressed forward and found a wonderful perl module to accomplish the desired task. See my sample code below.

use Geo::StreetAddress::US;
   my $full_address = "164 N Cherry Ln, 84660";
   my $address_parts = Geo::StreetAddress::US->parse_address($full_address);
   my $xml = ' <address streetno="'.$address->{number}.'" streetDir="'.$address->{prefix}.'" streetName="'.$address->{street}.'" streetType="'.$address->{type}.'" unit="" zip="'$address->{zip}'" yearsAtAddress=""/&rt;'
;

Make sure that you include city/state or Zip. Without it it will return undefined every time.
Thats it kiddies. Good luck and I hope that you never have to build an api for this client.

Labels: , , , , , , ,

0 Comments:

Post a Comment

<< Home