Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Looping through a binary file
by runrig (Abbot) on Sep 06, 2013 at 17:04 UTC | |
|
Re: Looping through a binary file
by Laurent_R (Canon) on Sep 06, 2013 at 17:46 UTC | |
|
Re: Looping through a binary file
by marinersk (Priest) on Sep 06, 2013 at 23:06 UTC | |
|
Re: Looping through a binary file
by daxim (Curate) on Sep 06, 2013 at 17:07 UTC | |
|
Re: Looping through a binary file
by Marshall (Canon) on Sep 07, 2013 at 10:26 UTC | |
|
Re: Looping through a binary file
by aitap (Curate) on Sep 08, 2013 at 19:03 UTC |