【发布时间】:2011-05-17 08:24:48
【问题描述】:
代码
$ 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 file diamond-operator