I'm new to Perl and running into difficulty with a Perl routine I've written. Basically, I have an EBCDIC file without carriage returns that is quite large. The routine I've written functions fine until I throw my "while" statement in at which point I get an "out of memory" error. Help pls! Thanks in advance..Chris
#!/usr/bin/perl use strict; use warnings; use lib '/home/q37j6m4/lib/'; # proceed as usual use Convert::IBM390 qw(:all); set_codepage('CP00037'); print "script to import pscmt.txt\n"; my $fileIN = "/sas/rbcpcins/ha/rawdata/pscmt.txt"; my $fileOUT = "/home/q37j6m4/test_out.txt"; my $fileLOG = "/home/q37j6m4/chris_log.txt"; my $recln =98; #length of file being imported open(perlIN,"<",$fileIN) or die "Can't open input.txt: $!"; open(perlOUT, ">",$fileOUT) or die "Can't open output.txt: $!"; open(perlLOG, ">>",$fileLOG) or die "Can't open my.log: $!"; while(<perlIN>) { print $index,"\n"; # pre-define fields my $cltno2 =""; my $cmtseq =""; my $npseqn =""; my $comm =""; my $policy =""; my $pdcode =""; my $userid =""; my $reccdt =""; my $recctm =""; my $cmgrcd =""; my $actcod =""; my $upid =""; # read fields read(perlIN,$cltno2,5); read(perlIN,$cmtseq,5); read(perlIN,$npseqn,3); read(perlIN,$comm,45); read(perlIN,$policy,8); read(perlIN,$pdcode,3); read(perlIN,$userid,10); read(perlIN,$reccdt,5); read(perlIN,$recctm,6); read(perlIN,$cmgrcd,1); read(perlIN,$actcod,3); read(perlIN,$upid,4); # convert fields my $cltno2_c = unpackeb('p5',$cltno2); my $cmtseq_c = unpackeb('p5',$cmtseq); my $npseqn_c = unpackeb('p3',$npseqn); my $comm_c = eb2asc($comm); my $policy_c = eb2asc($policy); my $pdcode_c = eb2asc($pdcode); my $userid_c = eb2asc($userid); my $reccdt_c = unpackeb('p5',$reccdt); my $recctm_c = eb2asc($recctm); my $cmgrcd_c = eb2asc($cmgrcd); my $actcod_c = eb2asc($actcod); my $upid_c = unpackeb('p4',$upid); # write fields print perlOUT sprintf ("%12.0f", $cltno2_c); print perlOUT sprintf ("%12.0f", $cmtseq_c); print perlOUT sprintf ("%12.0f", $npseqn_c); print perlOUT $comm_c; print perlOUT $policy_c; print perlOUT $pdcode_c; print perlOUT $userid_c; print perlOUT sprintf ("%12.0f", $reccdt_c); print perlOUT sprintf ("%12.0f", $recctm_c); print perlOUT $cmgrcd_c; print perlOUT $actcod_c; print perlOUT sprintf ("%12.0f", $upid_c); print perlOUT "\r\n"; } # end while loop close perlIN; close perlOUT; close perlLOG;

In reply to Looping through a binary file by Anonymous Monk

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.