open(F1,">test.dat");
open(F,"test.txt");
while()
{
/^(S{1})/i;
$hash_segment{$1}++;
print F1;
}
close(F);
close(F1);
open(F,"test.dat");
while()
{
/^(S{1})/i;
if ($hash_segment{$1}<=2)
{
if (!exists($hash_new{$1}))
{
$filename='valid'.$1.'.dat';
open (FO,">$filename");
}
$hash_new{$1}='';
print FO;
}
else
{
$hash_rest{$1}='';
}
}
close(F);
undef %hash_new;
undef %hash_segment;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/94041/viewspace-900276/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/94041/viewspace-900276/
本文介绍了一个使用Perl脚本处理两个文本文件的具体案例。脚本首先打开并读取'test.txt'的内容,对特定模式进行计数,并将结果写入'test.dat'。随后再次读取'test.dat',根据先前的计数结果进一步处理数据。
1018

被折叠的 条评论
为什么被折叠?



