0

これが私が持っているものです。

#!/usr/bin/perl

$numbertotal = 0;
$filecount = 0;

open my $thisfile, '<', "files.txt" or die $!;

while (<$thisfile>) {
    ($thisdate, $thistime, $thisampm, $thissize, $thisname) = split;

    $numbertotal += $thissize;
    $filecount += 1;
    printf "%10d     %-25.25s\n", $thissize, $thisname;
}

$averagefilesize = $numbertotal / $filecount;

print "Total files:  ",$filecount,"      Average file size:  ",$averagefilesize," bytes\n";

2 つの異なる印刷行を取り、コードによって作成される別のファイルに送信したいと思います。「<」操作を使用することは知っていますが、それを理解するのに問題があります。

どんな助けでも大歓迎です。ありがとう。

4

1 に答える 1

1

ファイルに書き込むには、次のコマンドで開きます'>':

open my $thisfile, '<', "files.txt" or die $!;
open my $thatfile, '>', 'output.txt' or die $!;

while (<$thisfile>) {
    ($thisdate, $thistime, $thisampm, $thissize, $thisname) = split;

    $numbertotal += $thissize;
    $filecount += 1;
    printf $thatfile "%10d     %-25.25s\n", $thissize, $thisname;
}
close $thatfile;
close $thisfile;
于 2013-11-04T17:08:02.903 に答える