When we pass the file name (include full path) as parameter,It will give us the size of the file and last modified time.
sub getFileStats { my $filename = $_[0]; ## includes full path my $not_applicable = 'N/A'; # get the stats. This returns nulls if no file exists my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($filename); if($mtime != undef) { # format datetime my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime($mtime); $year += 1900; if ($min < 10) { $min = "0$min"; } $mon = $mon + 1; ## zero based my $str_time = "$mon/$mday/$year $hour:$min"; return ($size, $str_time); } else { return ($not_applicable, $not_applicable); } #------------------------------------------------------------------- # For reference here are the stats we get for this filename # # 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 (NOT creation time!) in seconds since the epoch # 11 blksize preferred block size for file system I/O # 12 blocks actual number of blocks allocated }