这段Perl代码是否符合它的要求?

时间:2016-04-11 03:45:30

标签: perl

在搜索某些内容时,我发现了这个答案here

我想知道为什么变量2016-04-06 160 2016-04-07 170 2016-04-08 142 只包含输入文件的第一行。

代码:

$first_line

据我了解,#!/usr/bin/env perl use strict; my $filename = shift; open my $in_fh, '<', $filename or die "Cannot open $filename for reading: $!"; my $first_line = <$in_fh>; open my $out_fh, '>', "$filename.tmp" or die "Cannot open $filename.tmp for writing: $!"; $first_line =~ s/some translation/goes here/; print {$out_fh} $first_line; print {$out_fh} $_ while <$in_fh>; # sysread/syswrite is probably better close $in_fh; close $out_fh; # overwrite original with modified copy rename "$filename.tmp", $filename or warn "Failed to move $filename.tmp to $filename: $!"; 的整个内容都存储在$in_fh

0 个答案:

没有答案