私は Perl を初めて使用し、精神的な障害にぶつかりました。以下に示すように、タブ区切りファイルから情報を抽出する必要があります。
#name years risk total
adam 5 100 200
adam 5 50 100
adam 10 20 300
bill 20 5 100
bill 30 10 800
この例では、タブ区切りのファイルに、投資期間、危険にさらされた金額、および投資終了時の合計が表示されます。
このファイルを解析し、各名前 (例: adam ) について、投資年数の合計5+5を計算し、収益の合計(200-100) + (100-50) + (300-20)を計算します。また、名前ごとの合計 (200、100、300) も保存したいと思います。
これまでに試したことは次のとおりです。
my $filename;
my $seq_fh;
open $seq_fh, $frhitoutput
or die "failed to read input file: $!";
while (my $line = <$seq_fh>) {
chomp $line;
## skip comments and blank lines and optional repeat of title line
next if $line =~ /^\#/ || $line =~ /^\s*$/ || $line =~ /^\+/;
#split each line into array
my @line = split(/\s+/, $line);
my $yeartotal = 0;
my $earning = 0;
#$line[0] = name
#$line[1] = years
#$line[2] = start
#$line[3] = end
while (@line[0]){
$yeartotal += $line[1];
$earning += ($line[3]-$line[2]);
}
}
私が間違っていた場所のアイデアはありますか?