perl function stat
www.igifditea.com
The stat
function in Perl is used to retrieve file or file system status information. It returns a list of values that contain information about the file, such as its size, ownership, permissions, and timestamps.
Here's an example of using the stat
function:
my $file = 'example.txt'; my @file_info = stat($file); print "File size: " . $file_info[7] . "\n"; print "Owner UID: " . $file_info[4] . "\n"; print "Last access time: " . $file_info[8] . "\n";
Output:
File size: 50 Owner UID: 501 Last access time: 1643861841
In this example, we have a file named example.txt
. We use the stat
function to retrieve the file status information and assign the results to an array @file_info
.
We then print out some of the file status information using the array indices. $file_info[7]
gives us the file size, $file_info[4]
gives us the owner's user ID, and $file_info[8]
gives us the last access time of the file.