Further to the good advice you have been given regarding the use of unpack and arrays, there are a few other potential issues with your code.

Firstly, your local $/ ... is not really local unless you confine the scope to a bare block, e.g.

... { local $/ = \1173; ... } ...

Getting into the habit of doing this will minimise the risk of unwanted side effects if reading from another file handle later in the script.

Secondly, I would recommend the use of the three argument form of open and lexical rather than package filehandles. Also, you only check for success on one of your open statements and neither of your closes. E.g.

... my $inputFile = q{C:/INPUTFILE}; open my $inputFH, q{<}, $inputFile or die qq{open: < $inputFile: $!\n}; my $outputFile = q{C:/OUTPUT.TXT}; open my $outputFH, q{>}, $outputFile or die qq{open: > $outputFile: $!\n}; ... while( <$inputFH> ) ... print $outputFH ... ... close $inputFH or die qq{close: < $inputFile: $!\n}; close $outputFH or die qq{close: > $outputFile: $!\n};

Thirdly, you should consider separating the skipping of the first seven records from reading the rest of the records so as to avoid testing whether to skip for every read, and do you actually use $rcount for anything other than the record skipping?. I'm not sure of the logic you use when incrementing $rcount so below I show the way I'd tackle it.

... my $rcount; { local $/ = \1173; my $discard = <$inputFH> for 1 .. 7; $rcount = 7; # We've seen and skipped 7 records so far. while( <$inputFH> ) { $rcount ++; my @fields = unpack q{A34 ... }, $_; ... } } ... # Do something with $rcount here? ...

I hope these points are of interest.

Cheers,

JohnGG


In reply to Re: Seperating Fixed Line Feed into Fields by johngg
in thread Seperating Fixed Line Feed into Fields by drodinthe559

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.