Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl:如何在数组中逐行存储文件,并只读取数组的最后4行_Perl - Fatal编程技术网

Perl:如何在数组中逐行存储文件,并只读取数组的最后4行

Perl:如何在数组中逐行存储文件,并只读取数组的最后4行,perl,Perl,Perl:如何在数组中逐行存储文件,并只读取数组的最后4行 现在,我想将几个值与数组的最后4个值进行比较。以下是将整个文件读入数组的快速方法: use feature qw( say ); my @text = do { local @ARGV = $file ; <> }; say "@text[-4 .. -1]"; # last 4 lines of the array say "@text[($#text-3) ..

Perl:如何在数组中逐行存储文件,并只读取数组的最后4行


现在,我想将几个值与数组的最后4个值进行比较。

以下是将整个文件读入数组的快速方法:

use feature qw( say );
my @text = do { local @ARGV = $file ; <> };
say "@text[-4 .. -1]";               # last 4 lines of the array
say "@text[($#text-3) .. $#text]";   # same
say $text[-1];                       # last line of the file
say $text[-4];                       # 4th line from the end of the file
使用功能qw(比如说);
my@text=do{local@ARGV=$file;};
说“@text[-4..-1]”#数组的最后4行
说“@text[($#text-3)$#text]”;#相同的
说$text[-1];#文件的最后一行
说$text[-4];#文件末尾的第四行

my@array=将从打开的文件中读取所有行
$array[-1]
提供数组中的最后一行。我想你已经得到了剩下的。@Siphali请确保你也粘贴了代码(你已经尝试过了)。这将帮助人们发现/回答您在脚本方面面临的问题。