Perl stat Function
This function returns a 13-element array giving the status info for a file, specified by either FILEHANDLE, EXPR, or $_. The list of values returned is shown below in Table. If used in a scalar context, returns 0 on failure, 1 on success.
Note that support for some of these elements is system dependent.check the documentation for a complete list.
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
Following is the simple syntax for this function −
stat FILEHANDLE stat EXPR stat
This function returns ARRAY, ($device, $inode, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks)
Following is the example code showing its basic usage −
#!/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");
When above code is executed, it produces the following result −
stat() 64776, 402653494, 1464186215