Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Fun exercise, here was my approach, I make the assumption that the last block of data is your city_state_zip jumble and the first block is your customer, everything else in the middle is addressing info. Then I pull everything apart from its ends city_state zip then I have to make the horrible assumption that there is a state code... in either case, I can still put city_state together which you can see in the dump if you uncomment it. About as fancy as I care to get in 25 mins. Cheers.
use strict; use Data::Dumper; my @customers; while(<DATA>){ my %customer; my (@data) = split /[\t]/, $_; my $city_state_zip; my $which = 0; for( 1..$#data){ $which = $#data -$_; $city_state_zip = $data[-$_]; last if ( $city_state_zip =~/\w+/ig ); } $customer{name} = $data[0]; for( 1..5){ if( $_ <= $which ){ $customer{qq/address$_/} = $data[$_]; } else { $customer{qq/address$_/} = "NULL"; } } $customer{city_state_zip} = $city_state_zip; push @customers, \%customer; } foreach my $c ( @customers ){ my ($city_state, $zip ) = ($1, $2, $3) if $c->{city_state_zip} =~/(.*)\s+([\d\-]+)/g; my ($city, $state) = ($`, $1) if $city_state =~/\s(\w+)$/; $c->{city} = $city; $c->{state} = $state; $c->{zip} = $zip; print " $c->{name}$c->{address1} $c->{address2} $c->{address3} $city, $state $zip\n"; } #print Dumper(\$customers[0]); __DATA__ BIGGLE EQUITY MGMT ASSOC. PIGGLE BIGGLING PLAN FUTURES I & II + TWO LONDDDD CENTER TRENTON NJ 97302-5115 AGRICULTURAL LIFE INSURANCE CO MAIN 111 ELEVEN AVE PO BOX 123 + MORRISTOWN NJ 97631-0633 MILLENA BANC MILLINER BANK & TRUST CO 456 THAUMATURGE AVENUE + NEWSOME MA 07145-6316 BRICKABRACK ADVISORS LIBERTARIAN BANK 888 CRAZED CREEK ROAD ST +E 11 MEMPHIS KY 77882-5394 FOO COMMUNITY BANCORP THE FOOVILLE SAVINGS BANK 18 FOOL AVENUE + FOO NY 10567-1735 ELROND ASSET MANAGEMENT BRA3255 CSHYTFD ATTN SETTLEMENTS DEPT. + 466 LURCHING AVENUE NEW YORK NY 10347 CRIPPLE CREEK INVESTMENT ADVISORS GLIB TALKER 666 9TH AVENUE 8 +TH FLOOR NEW YORK NY 10235-2302 SEPARATIST STATE BANK ATTN: JOSE KWAN XYZ FINANCIAL CENTER + 145 TALKING FAST ROAD NEWBURGH NY 07083-2340

I wanted to add that, I think the way Perl allows you to develop solutions to real world problems like this so quickly and elegantly speaks volumes of praise for the mountain of programmers that built this language. I don't think I have seen a closer knit community of folks so willing to help other programmers learn and develop than right here on Perl Monks either. :0) Super!
JamesNC

In reply to Re: Data Salad Address Problem by JamesNC
in thread Data Salad Address Problem by SamCG

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (9)
As of 2024-04-18 16:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found