【发布时间】:2015-05-31 03:34:10
【问题描述】:
我正在处理一个 16GB 的文件和一个小文件。
我尝试将这两个文件加载到内存中。然后,我在大文件的每一行上移动并验证小文件中的某些内容(对于我在小文件上迭代的大文件中的每一行)。
这是我的代码
local $/ = undef;
open my $fh1, '<', $in or die "error opening $in: $!";
my $input_file = do { local $/; <$fh1> };
local $/ = undef;
open my $fh2, '<', $handle or die "error opening $handle: $!";
my $handle_file = do { local $/; <$fh2> };
my $counter_yes = 0;
my $counter_no = 0;
my $flag = 0;
my @lines1 = split /\n/, $input_file;
foreach my $line( @lines1 ) {
my @f = split('\t', $line); # $f[0] and $f[1]
print "f0 and f1 are: $f[0] and $f[1]\n";
my @lines2 = split /\n/, $handle_file;
foreach my $input ( @lines2 ){
#print "line2 is: $input\n";
my @sp = split /:/, $input; # $sp[0] and $sp[1]
if ( $sp[0] eq $f[0] ){
my @r = split /-/, $sp[1];
if ( ($f[1] >= $r[0]) && ($f[1] <= $r[1]) ){
$flag = 1;
$counter_yes = $counter_yes;
last;
}
}
}
if ( $flag == 0 ){
$counter_no = $counter_no ;
}
}
当我运行它时,我得到了错误
Split loop at script.pl line 30, <$fh2> chunk 1
可能是什么原因?
【问题讨论】:
-
您可以尝试添加使用字节;脚本顶部的编译指示。可能是编码问题。
-
把你的代码放在你的问题中。 ...另外,我为你的数据哭泣。