我正在尝试使用来自另一个文件的输入输出到一个文件。没有键盘输入。
我知道我走在正确的轨道上,我的语法有点不对劲。
基本上,我从文件“boot.log”中获取记录,使用模式匹配选择某些记录并将它们输出到名为“bootlog.out”的文件中。我还没有进入模式匹配部分。这就是我所拥有的...
open (BOOTLOG, "boot.log") || die "Can't open file named boot.log: $!";
while ($_ = <BOOTLOG>)
{
print $_;
}
open (LOGOUT, ">bootlog.out") || die "Can't create file named bootlog.out: $!\n";
close (LOGOUT) || die "Can't close file named bootlog.out: $!\n";
close (BOOTLOG) || die "Can't close the file named boot.log: $!";
如何将 boot.log 的内容打印到 bootlog.out?
编辑1
这似乎接受输入并将其输出到第二个文件。语法是否正确?
open (BOOTLOG, "boot.log") || die "Can't open file named boot.log: $!";
open (LOGOUT, ">bootlog.txt") || die "Can't create file named bootlog.out: $!\n";
while ($_ = <BOOTLOG>)
{
print $_;
print LOGOUT $_;
}
close (LOGOUT) || die "Can't close file named bootlog.txt: $!\n";
close (BOOTLOG) || die "Can't close the file named boot.log: $!";