计算数组长度的perl脚本实例,代码如下:
复制代码 代码示例:
#!/usr/bin/perl
#edit www.jb200.com
open(FILE1,"C:/Perl/BX/BX-Book-Ratings_result.txt");
open(FILE2,"C:/Perl/BX/BX-Users_result.txt");
open(result1,">C:/Perl/BX/BX-Book-Ratings_short.txt");
open(result2,">C:/Perl/BX/BX-Users_short.txt");
my @ISBN;
my $isbnNum=0;
my $i=0;
my $user;
my $subString;
my $count=0;
while(($_=<FILE1>)&&($user=<FILE2>))
{
$subString=substr($_,index($_,",")+1);
@ISBN=split(/ /,$subString);
$isbnNum=scalar(@ISBN);
if($isbnNum>4)
{
syswrite(result1,"$_");
syswrite(result2,"$user");
$count++;
}
else
{
next;
}
#printf"@ISBN $isbnNum $user";
#$i++;
}
printf"$count";
close(FILE1);
close(FILE2);
close(result1);
close(result2);