|
|
OverviewDisplay the file size of a file.
Flow
A sample code
my $size = (stat("$file"))[7];
print "$file size:$size byte";
Description of the code
my $size = (stat("$file"))[7];
$file is the file from which you want to obtain the size. The stat function is used to get the attributes. The eighth element(element number 7) of the returned array indidates the file size. If you want to obtain all elements of the stat function,
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,
$mtime,$ctime,$blksize,$blocks)=stat("$file");
you can do as above. my $size = -s "$file"; -s operater can also be used to retrieve file size as above. print "$file size:$size byte"; Display the file size you obtained. |