Let me take another stab at explaining this. btw, I do not take your comments personal, I receive an electronic file generated by a third party. below if the fist line of that file. Whe pasting it here the carriage returns do not show up, but there is one following EACH tilde (~). the file contains a bit over 4300 lines similar to this one.
the REQUIREMENTS are:
1 - remove all carriage retuns (in vb this would be chr(10)
2 - format the remaining text (including any special characters, and tildes) into 80 characters per line. Breaks in the middle of words or other string combinations is permissible.
3 - This process should be able to be used for other files specified on a command line ie. <perlscriptname> <inputfilename> <outputfilename>
As you pointed out the first line breaks at position 79 text::wrap:columns=80 Where column lenght is X - 1 thus 79.
the next line as again you point out breaks at position 49 when the entire thing is only 64 positions (WHY) THIS IS MY PROBLEM.
I did not understand that the module text::wrap broke on whole words only. If this is the case and it uses spaces to determine a word break, why does the first line work as expected - it may be moot.
If you see another approach to achieving my requirements, please let me know. --- Thanks
The code immediately below this is where I am at:
#! / usr/bin/perl -w
use Text::Wrap qw(wrap);
#
$name = $ARGV[0];
$name1 = $ARGV[1];
#
#
open (INFILE, "<$name");
open (OUTFILE, ">$name1");
$Text::Wrap::columns = 80;
while (my $row = <INFILE>) {
print OUTFILE wrap('','',$row) ;
}
close (INFILE);
close (OUTFILE);
The
Inputfile sample ->
ISA*00* *00* *28*9000000454 *ZZ*J00370 *
+070926*0342*U*00401*000489661*0*P*:~
GS*HP*9000000454*J00370*20070926*03421826*489660*X*004010X091A1~
ST*835*489662~
BPR*I*6519.36*C*ACH*CCP*01*075906003*DA*0000194917*1351840597*00454
+ *01*021000021*DA*304677450*20070926~
TRN*1*EFT2545408*1351840597*00454~
DTM*405*20070925~
N1*PR*NATIONAL GOVERNMENT SERVICES 00454~
N3*5151 CAMINO RUIZ~
N4*CAMARILLO*CA*930128645~
REF*2U*00454~
N1*PE*GOLDEN LIVINGCENTER FOLEY*FI*204120517~
N3*1000 FIANNA WAY~
N4*FORT SMITH*AR*72919~
REF*PQ*015032~
LX*210712~
TS3*015032*21*20071231*8*19760.22*9175.8*10584.42**8905.8**-2334****91
+75.8*2604*******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*BRADY*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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.