Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • 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 imbibing at the Monastery: (3)
As of 2024-04-19 18:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found