Hi all,

I need to keep address lines in a file at a maximum of 30 characters. I have a file with these columns:

Address_Line_1 (this is never blank) Address_Line_2 (this could be blank) Address_Line_3 (this could be blank) Address_Line_4 (this is never blank) City (this is never blank) State (this is never blank) Zip (this is never blank)

I am looking to use perl to check if Address_Line_2 is greater than 30 characters.

If it is, I need to divide Address_Line_2 between Address_Line_2 and Address_Line_3, but only if Address_Line_3 is blank.

If I need to divide Address_Line_2, I would like to divide it at a point in where there is a space.

I'm reading the file in like this:
while (<INFILE>) { @fields = split /\t/, $_; $a1 = $fields[0]; $a2 = $fields[1]; $a3 = $fields[2]; $a4 = $fields[3]; $city = $fields[4]; $st = $fields[5]; $zip = $fields[6]; print OUTFILE pack ("A30", $a1); print OUTFILE $TAB; print OUTFILE pack ("A30", $a2); print OUTFILE $TAB; print OUTFILE pack ("A30", $a3); print OUTFILE $TAB; print OUTFILE pack ("A30", $a4); print OUTFILE $TAB; print OUTFILE pack ("A16", $city); print OUTFILE $TAB; print OUTFILE pack ("A2", $st); print OUTFILE $TAB; print OUTFILE pack ("A10", $zip); print OUTFILE "\r\n"; }
Many Thanks!

In reply to Dividing up Long Lines by moe79

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.