Perl语言入门级问题,求编译一个用于合并两个文本文件的简易程序

2024-11-17 03:24:20
推荐回答(1个)
回答1:

#!/usr/bin/perl
$#ARGV != 2 || die "Number of parameters is not 2(only 2)!\n";
$filea=$ARGV[0];
$fileb=$ARGV[1];
open(CHINESE,$filea)||die "Can't open $filea: $!\n";
$cnta=0;
while(){
chomp(@reca[$cnta]=$_);
$cnta+=1;
}
close CHINESE;
open(ENGLISH,$fileb)||die "Can't open $fileb: $!\n";
$cntb=0;
while(){
chomp(@recb[$cntb])=$_);
$cntb+=1;
}
close ENGLISH;
$max=$cnta>$cntb?$cnta:$cntb;
for($i=0;$i<$max;$i++){
print "@reca[$i]\n@recb[$i]\n\n";
}