in reply to Re^10: 80 characters long
in thread 80 characters long
First, you mean "Line Feed" (chr(10)), not "Carriage Return" (chr(13)).
Second, providing the desired output along with a sample input is very useful, especially when you have problems explaining what you want.
Finally, we've coverered that Text::Wrap broke on word boundaries on the first day, before you even started using Text::Wrap. Not only did I say "Text::Wrap will only break on a word boundary.", I provided code that broke on the 80th column unconditionally.
Let's go back to that code and fix it for the then-unmentioned requirements to remove existing line breaks.
my $text = do { local $/; <> }; $text =~ tr/\n//d; $text =~ s/(.{80})/$1\n/g; $text =~ s/(?!<\n)\z/\n/; print($text);
Usage:
perl script.pl infile > outfile
Or if you want to modify it in-place:
perl -i.bak script.pl file
Output for provided input:
ISA*00* *00* *28*9000000454 *ZZ*J00370 * +070926*034 2*U*00401*000489661*0*P*:~GS*HP*9000000454*J00370*20070926*03421826*48 +9660*X*004 010X091A1~ST*835*489662~BPR*I*6519.36*C*ACH*CCP*01*075906003*DA*000019 +4917*13518 40597*00454 *01*021000021*DA*304677450*20070926~TRN*1*EFT2545408*13 +51840597*0 0454~DTM*405*20070925~N1*PR*NATIONAL GOVERNMENT SERVICES 00454~N3*515 +1 CAMINO R UIZ~N4*CAMARILLO*CA*930128645~REF*2U*00454~N1*PE*GOLDEN LIVINGCENTER F +OLEY*FI*20 4120517~N3*1000 FIANNA WAY~N4*FORT SMITH*AR*72919~REF*PQ*015032~LX*210 +712~TS3*01 5032*21*20071231*8*19760.22*9175.8*10584.42**8905.8**-2334****9175.8*2 +604******* 8*8905.8~TS2*11509.8**********2*41*41~CLP*0073294416 070299289*19*856. +96*769.14* *MA*20725800001702*21*2~CAS*CO*94*-284.18~CAS*PR*2*372*0~NM1*QC*1*BRAD +Y*LEO*F*** HN*140079398A~NM1*82*2*GOLDEN LIVINGCENTER FOLEY*****XX*1538110192~NM1 +*TT*2*WPS - TRICARE FOR LIFE*****PI*000060000~MIA*0***1141.14*MA02**********3*** +**MA44~REF *EA*0073294416~DTM*050*20070913~DTM*23
|
|---|