我创建了一个 Perl 脚本,用于读取包含一些数字的文件,一个在另一个之下。我想消除重复并将新列表保存到文件中。这是我的脚本:
use strict;
my $arg = "<abs path to>\\list.txt";
open (FH, "$arg") or die "\nError trying to open the file $arg : $!";
print "Opened File : $arg\n";
my $line = "";
my @lines = <FH>;
close FH;
my $temp;
my $count = 0;
my $check = 0;
my @list;
my $flag;
for $line (@lines)
{
$count += 1;
$check = $count;
$flag = 1;
for my $next (@lines)
{
$check -= 1;
if($check < 0)
{
if ($line == $next)
{
$flag = 0;
}
}
}
if($flag == 1)
{
push (@list, $line);
}
}
my $newarg = "<abs path to>\\new_list.txt";
open (FWH, ">>$newarg") or die "\nError trying to open the file $newarg for writing : $!";
my $size = @list;
print FWH "\n\n*** Size = $size ***\n\n";
for my $line (@list)
{
print FWH "$line";
}
我是一个尝试学习 Perl 的 C++ 人。所以你能不能给我推荐一些 Perl 中的 API,它可能会减少脚本的大小。我希望脚本可读且易于快速理解,因此需要间距。谢谢你。