Hello everyone, I am trying to convert my file into a comma delimited file but I am having trouble with the unpack and print. I have set my fields and set my unpack field characters, but when I run the process I get no results. Any help would be great.

use strict; use warnings; open (NEW, ">", "WK_OUTPUT_TEST.txt" ) or die "could not open:$!"; open (FILE, "<", "WK_OUTPUT.txt") or die "could not open:$!"; while (<FILE>) { $line = $_; $line .= ‘ ‘ x (280 – length($line)); #single space between th +e ‘ ‘ ($acct, $name, $ddte, $amt1, $amt2, #amt3, $can, $note, $ndte, + $bar, $ins) = unpack(‘A10A50A8A10A10A10A8A30A8A8A8’, $line); Print NEW “\"$acct\",”; Print NEW “\”$name\”,”; Print NEW “$ddte,”; Print NEW “$amt1,”; Print NEW “$amt2,”; Print NEW “$amt3,”; Print NEW “\"$can\”,”; Print NEW “\"$note\”,”; Print NEW “$ndte,”; Print NEW “\"$bar\”,”; Print NEW “\"$ins\”,”; Print NEW "\n"; } close (FILE); close (NEW)

INPUT FILE:

A123456789 DOE, JANE + 08/10/16 319.25 23.00 54.27 + CLMPD Claim paid correctly +per 08/15/17 BAR.ID HMO + A123456789 DOE, JANE + 08/10/16 23.00 54.27 + CLMPD + 08/15/17 + BAR.ID HMO A123456789 DOE, JANE + 08/10/16 319.25 54.27 + CLMPD Contract Calculation- + 08/15/17 BAR.ID

EXPECTED OUTPUT:

A123456785 “,” DOE, JANE “,” 08/10/16 ”,” 319.25 ”,” 23.00 "," 54.27 ” +,” CLMPD ”,” Claim paid correctly per ”,” 08/15/17 ”,” BAR.ID ”, +” HMO A123456786 “,” DOE, JANE “,” 08/10/16 ”,” ”,” 23.00 "," 54.27 ” +,” CLMPD ”,” ”,” 08 +/15/17 ”,” BAR.ID ”,” HMO A123456787 “,” DOE, JANE “,”08/10/16 ”,” 319.25 ”,” "," 54.27 ” +,” CLMPD ”,” Contract Calculation- ”,” 08/15/17 ”,” BAR.ID +”,” PPO

In reply to Unpack and Print NEW by jlope043

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.