Sample of perl format data file

#!../soft/perl/bin/perl
#ident  "%W%"
#format data file

my ($inputfile)=$ARGV[0];
my ($outfile)=$ARGV[1];

&getDatas();

sub getDatas{

#column size 5,2,2,2,6,8,5,15,1,30,30,10,10,10,8,23,20,2,4
#data size   5,2,2,2,6,8,5,20,1,30,30,3,10,10,8,26,20,2,4
@clmsLen=(5,2,2,2,6,8,5,20,1,30,30,3,10,10,8,26,20,2,4);
open(IN,">$outfile");
open(DATA,"$inputfile") || die "Required file not found \n";

while($input = <DATA>){
  chomp($input);
  $pos=0;
  $result="";
  foreach $len(@clmsLen){
      $result .= substr($input,$pos,$len) . "|";
      $pos=$pos+$len;
      }
  $result .="\n";
  printf IN $result;

}
close(IN);
close(DATA);
}
 

相关推荐