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); }
相关推荐
边城客栈学无止境 2020-07-05
Walter的学习笔记 2020-07-04
A宇 2020-06-14
边城客栈学无止境 2020-06-10
邓博学习笔记 2020-06-03
davidliu00 2020-05-26
ShiShuo 2020-05-16
Aggressivesnail 2020-05-10
ShiShuo 2020-04-26
hanxingwang00 2020-04-22
davidliu00 2020-03-06
ShiShuo 2020-03-06
ShiShuo 2020-03-05
Aggressivesnail 2020-02-28
aaLiweipeng 2020-02-01
amberom 2020-01-16
Walter的学习笔记 2020-01-06