将FileHandle引用为数组

时间:2011-05-05 11:05:33

标签: arrays perl pointers filehandle

鉴于我需要处理4GB文件,Perl中是否有一种方法可以像数组一样引用文件句柄而不将其复制到实际的数组/内存中?

类似的东西:

open (LOG, "less file.txt |");
my @reference = \<LOG>;
print $reference[1000000];
close LOG;

谢谢!!

1 个答案:

答案 0 :(得分:7)

使用Tie::File

use Tie::File;
tie my @array, 'Tie::File', $filename or die "tie $filename: $!";

print $array[42];