Perl:如何在数组中逐行存储文件,并只读取数组的最后4行
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) ..
现在,我想将几个值与数组的最后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请确保你也粘贴了代码(你已经尝试过了)。这将帮助人们发现/回答您在脚本方面面临的问题。