I think the op's actually got a carriage-return separated file, if you view source. So I'm not absolutely sure on the format, but it looks like there are 5 lines per record, basically. The other thing is, do you now want the spouse and phone number in the pipe-separated records?

Anyway:

use strict; open FH, "foo" or die "Can't open: $!"; my @recs; while (<FH>) { chomp; push @{$recs[int(($.-1) / 5)]}, $_; } close FH or die "Can't close: $!"; open FH, ">foo.new" or die "Can't open: $!"; for my $ref (@recs) { # break up the city, state, zip into 3 parts my($city, $state, $zip); if ($ref->[2] =~ /(.*?),\s(.*?)\s(.*)/) { ($city, $state, $zip) = ($1, $2, $3); } # join it all together into a pipe-separated # record, then write it out my $new = join "|", @{$ref}[0,1], $city, $state, $zip, @{$ref}[3,4]; print FH $new, "\n"; } close FH;
I haven't tested this very thorougly, but it looks like it'll work. It's rather ugly, too. :)

In reply to Re: Simple Text Conversion by btrott
in thread Simple Text Conversion by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.