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:Many Thanks!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"; }
In reply to Dividing up Long Lines by moe79
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |