使用在Windows中通过批处理文件调用的Perl删除重复数据删除 Windows中的DOS窗口通过批处理文件调用。 批处理文件调用执行操作的Perl脚本。我有批处理文件。 我的工作重复数据的代码脚本是删除,只要数据文件不是太大。 需要解决的问题是数据文件较大(2 GB或更多),如果尝试将完整文件加载到数组以删除重复数据,则会发生此文件大小的内存错误。 在子程序时发生存储器错误: -如何从Perl的大文件中删除非唯一的行?
@contents_of_the_file = <INFILE>;
(A完全不同的方法是可接受的,只要它解决此问题,请建议)。 子程序是: -
sub remove_duplicate_data_and_file
{
open(INFILE,"<" . $output_working_directory . $output_working_filename) or dienice ("Can't open $output_working_filename : INFILE :$!");
if ($test ne "YES")
{
flock(INFILE,1);
}
@contents_of_the_file = <INFILE>;
if ($test ne "YES")
{
flock(INFILE,8);
}
close (INFILE);
### TEST print "$#contents_of_the_file\n\n";
@unique_contents_of_the_file= grep(!$unique_contents_of_the_file{$_}++, @contents_of_the_file);
open(OUTFILE,">" . $output_restore_split_filename) or dienice ("Can't open $output_restore_split_filename : OUTFILE :$!");
if ($test ne "YES")
{
flock(OUTFILE,1);
}
for($element_number=0;$element_number<=$#unique_contents_of_the_file;$element_number++)
{
print OUTFILE "$unique_contents_of_the_file[$element_number]\n";
}
if ($test ne "YES")
{
flock(OUTFILE,8);
}
}
+1用于实际构建代码。 – 2009-09-24 17:43:07
只要被哈希的行是16个字符或更大,这将是一个胜利。如果行长度小于16,则使用该行本身而不是'%seen'键。 my $ hashed_line = length($ line)> 15? md5($ line):$ line; 将做的伎俩。另请参阅'Bit :: Vector'作为'%keep_line_num'的替代,以减少内存占用。 – dland 2009-09-26 17:15:55