I been trying to fixup web intergration of an OLD MS-DOS system, that uses fixed record length files ascii text files to store data.

the file im trying to convert is located at http://www.mscorp.org/bksic.txt

my desired output is to take every field defined except those labeled as trash in my perl code, and cut the spaces off the front and end then but a pipe between each field. and save the output fo a file.

Any advise would help. My perl code is below.

#LOAD REQUIRED PACKAGES & SET GLOBAL VARIABLES $file = "bksic.txt"; $outfile = "bksic.out"; #READ & PARSE STOCK INVENTORY CONTROL #DEFINE FIELDS @BKSIC_MFG = (); @BKSIC_MODEL = (); @BKSIC_SPEC1 = (); @BKSIC_SPEC2 = (); @BKSIC_SPEC3 = (); @BKSIC_SPEC4 = (); @BKSIC_OPT1 = (); @BKSIC_OPT2 = (); @BKSIC_OPT3 = (); @BKSIC_OPT4 = (); @BKSIC_DESC = (); @BKSIC_QOH = (); @BKSIC_TRASH1 = (); @BKSIC_MULT = (); @BKSIC_TRASH2 = (); @BKSIC_LIST = (); @BKSIC_TRASH3 = (); #OPEN, READ & PARSE DATAFILE open(DATAFILE,"<$file") || die "I can NOT open $file please fix the pr +oblem!\n"; @products = (); while ($line=<DATAFILE>) { if ((substr($line, 3, 50)) !~ /COMPONENT PARTS/) { push (@products, $line); } } close (DATAFILE); $i = 0; foreach $line (@products){ ($BKSIC_MFG[$i]) = substr ($line, 0, 3) =~ m/^\s*(.*)\ +s*$/; ($BKSIC_MODEL[$i]) = substr ($line, 3, 50) =~ m/^\s*(. +*)\s*$/; ($BKSIC_SPEC1[$i]) = substr ($line, 53, 7) =~ m/^\s*(. +*)\s*$/; ($BKSIC_SPEC2[$i]) = substr ($line, 60, 7) =~ m/^\s*(. +*)\s*$/; ($BKSIC_SPEC3[$i]) = substr ($line, 67, 7) =~ m/^\s*(. +*)\s*$/; ($BKSIC_SPEC4[$i]) = substr ($line, 74, 7) =~ m/^\s*(. +*)\s*$/; ($BKSIC_OPT1[$i]) = substr ($line, 81, 6) =~ m/^\s*(.* +)\s*$/; ($BKSIC_OPT2[$i]) = substr ($line, 87, 6) =~ m/^\s*(.* +)\s*$/; ($BKSIC_OPT3[$i]) = substr ($line, 93, 6) =~ m/^\s*(.* +)\s*$/; ($BKSIC_OPT4[$i]) = substr ($line, 99, 6) =~ m/^\s*(.* +)\s*$/; ($BKSIC_DESC[$i]) = substr ($line, 105, 55) =~ m/^\s*( +.*)\s*$/; ($BKSIC_QOH[$i]) = substr ($line, 160, 4) =~ m/^\s*(.* +)\s*$/; ($BKSIC_TRASH1[$i]) = substr ($line, 164, 41) =~ m/^\s +*(.*)\s*$/; ($BKSIC_MULT[$i]) = substr ($line, 205, 6) =~ m/^\s*(. +*)\s*$/; ($BKSIC_TRASH2[$i]) = substr ($line, 211, 23) =~ m/^\s +*(.*)\s*$/; ($BKSIC_LIST[$i]) = substr ($line, 234, 7) =~ m/^\s*(. +*)\s*$/; ($BKSIC_TRASH3[$i]) = substr ($line, 241, 169) =~ m/^\ +s*(.*)\s*$/; $i++; } open(DATAFILE,">>$outfile") || die "I can NOT open $outfile please fix + the problem!\n"; $i = 0; $x = @products; while ($i <= $x) { print DATAFILE "$BKSIC_MFG[$i]|$BKSIC_MODEL[$i]|$BKSIC_SPEC1[$ +i]|$BKSIC_SPEC2[$i]|$BKSIC_SPEC3[$i]|$BKSIC_SPEC4[$i]|$BKSIC_OPT1[$i] +|$BKSIC_OPT2[$i]|$BKSIC_OPT3[$i]|$BKSIC_OPT4[$i]|$BKSIC_DESC[$i]|$BKS +IC_QOH[$i]|$BKSIC_TRASH1[$i]|$BKSIC_MULT[$i]|$BKSIC_TRASH2[$i]|$BKSIC +_LIST[$i]|$BKSIC_TRASH3[$i]|\n"; $i++; } close (DATAFILE);

In reply to Converting fixed record length files to pipe delimited by akm2

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.