Free Perl Tutorials

stat function in PERL

What is the stat function in PERL? The stat function is a great little tool that returns the statistics on a particular file, expression, or directory. It lists the information on any one of 13 elements from a file, expression, or directory. The 13 elements to choose between are listed below:

0 dev device number of filesystem
1 ino inode number
2 mode file mode (type and permissions)
3 nlink number of (hard) links to the file
4 uid numeric user ID of file's owner
5 gid numeric group ID of file's owner
6 rdev the device identifier (special files only)
7 size total size of file, in bytes
8 atime last access time in seconds since the epoch
9 mtime last modify time in seconds since the epoch
10 ctime inode change time in seconds since the epoch (*)
11 blksize preferred block size for file system I/O
12 blocks actual number of blocks allocated

stat function usage:

$example = (stat $file-to-get-stats-from)[number of the element you want returned from above list];

So, your actual code might look something like this for the stat function in PERL:

$example = (stat $file)[10];


That's all there is to using the stat function in PERL!