Perl stat 函数

  • 描述

    stat 此函数返回一个由13个元素组成的数组,该数组给出文件的状态信息,由FILEHANDLE,EXPR或$_指定。返回的值列表如下表所示。如果在标量上下文中使用,则失败时返回0,成功时返回1。请注意,对其中某些元素的支持取决于系统。检查文档以获取完整列表。
    
    Element Description
    0       Device number of file system
    1       Inode number
    2       File mode (type and permissions)
    3       Number of (hard) links to the file
    4       Numeric user ID of file.s owner
    5       Numeric group ID of file.s owner
    6       The device identifier (special files only)
    7       File size, in bytes
    8       Last access time since the epoch
    9       Last modify time since the epoch
    10      Inode change time (not creation time!) since the epoch
    11      Preferred block size for file system I/O
    12      Actual number of blocks allocated
    
  • 句法

    以下是此函数的简单语法-
    
    stat FILEHANDLE
    
    stat EXPR
    
    stat
    
  • 返回值

    此函数返回数组($device,$inode,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)
  • 示例

    以下是显示其基本用法的示例代码-
     
    ($device, $inode, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
       $ctime, $blksize, $blocks) = stat("/etc/passwd");
    
    print("stat() $device, $inode, $ctime\n");
    
    尝试一下
    执行以上代码后,将产生以下结果-
    
    stat() 2065, 5374250, 1508051555