使用在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