Perl将文件插入数组变量
示例
open(my $fh, '<', "/some/path") or die $!; my @ary = <$fh>;
在列表上下文中求值时,菱形运算符将返回一个由文件中所有行组成的列表(在这种情况下,将结果分配给数组供应列表上下文)。保留行终止符,并且可以通过砍除将其删除:
chomp(@ary); #removes line terminators from all the array elements.
open(my $fh, '<', "/some/path") or die $!; my @ary = <$fh>;
在列表上下文中求值时,菱形运算符将返回一个由文件中所有行组成的列表(在这种情况下,将结果分配给数组供应列表上下文)。保留行终止符,并且可以通过砍除将其删除:
chomp(@ary); #removes line terminators from all the array elements.