代码
$ cat test1
hello
i am
lazer
nananana
$ cat 1.pl
use strict;
use warnings;
my @fh;
open $fh[0], '<', 'test1', or die $!;
my @res1 = <$fh[0]>; # Way1: why does this not work as expected?
print @res1."\n";
my $fh2 = $fh[0];
my @res2 = <$fh2>; # Way2: this works!
print @res2."\n";
运行
$ perl 1.pl
1
5
$
我不确定为什么Way1
不能按预期工作,而Way2
可以。难道这两种方法不一样吗?发生了什么事情呢?
perl -le 'print for < < <=> > >'
- tchrist