$ 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
$
私はWay2
はありませんしながら、期待通りWay1
が動作しない理由はわかりません。それらの2つの方法は同じではありませんか?ここで何が起きてるの?そのため<>オペレータの二重性の
'perlの-le「印刷< < <=>用>>」' – tchrist
@tchrist:グロブの楽しい一例であること以外、他の任意のポイント? – runrig
いいえ、それは*ポイントでした。 :) – tchrist