當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Perl 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)

示例

以下是顯示其基本用法的示例代碼 -

#!/usr/bin/perl -w

($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

相關用法


注:本文由純淨天空篩選整理自 Perl stat Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。