いくつかの数字が上下に並んでいるファイルを読み取るための 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 を教えてください。スクリプトを読みやすく、簡単に理解できるようにしたいので、間隔を空けます。ありがとうございました。