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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.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:使用stat()_Perl_Filehandle - Fatal编程技术网

Perl:使用stat()

Perl:使用stat(),perl,filehandle,Perl,Filehandle,我试图在perl脚本中使用stat()。 我已经阅读了关于perldocs的文档,其中说要像这样使用它: $mode = (stat($filename))[2]; 但这不起作用: $mode = (stat($filename))[2]; print $mode; Use of uninitialized value $mode in print at ... 我认为需要另一种语法来访问stat返回的值。Data::dumper返回以下结构: @stat = stat($file

我试图在perl脚本中使用stat()。 我已经阅读了关于perldocs的文档,其中说要像这样使用它:

$mode = (stat($filename))[2];
但这不起作用:

$mode = (stat($filename))[2];
print $mode;

Use of uninitialized value $mode in print at ... 
我认为需要另一种语法来访问stat返回的值。Data::dumper返回以下结构:

   @stat = stat($filename);
   print Dumper(@stat);

  $VAR1 = bless( [
   48,
   305368,
   33188,
   1,
   0,
   0,
   0,
   '2011',
   1397569653,
   1397569653,
   1397569653,
   4096,
   8
  ], 'File::stat' );

显然,你也有这条线

use File::stat;
在你的节目里,忘了提了。使用返回对象的版本覆盖内置的
stat
函数。你应该改为阅读

在您的情况下,您需要:

use File::stat;

my $mode = stat($filename)->mode;

显然,你也有这条线

use File::stat;
在你的节目里,忘了提了。使用返回对象的版本覆盖内置的
stat
函数。你应该改为阅读

在您的情况下,您需要:

use File::stat;

my $mode = stat($filename)->mode;

您可以使用数组片(stat$filename)[2]

您可以使用数组片(stat$filename)[2]

读取错误的文档。查看文档,这是您在该示例中使用的。编辑后,问题出在哪里?stat函数返回一个数组,给出给定文件的状态信息。@PseftiS,否,它返回一个受祝福的arrayref。但是该语法期望
stat
返回一个列表。您阅读了错误的文档。查看文档,这是您在该示例中使用的。编辑后,问题出在哪里?stat函数返回一个数组,给出给定文件的状态信息。@PseftiS,否,它返回一个受祝福的arrayref。但是该语法期望
stat
返回一个列表。