| Search perlmeme.org | |
| Home » Faqs » File io » Filesize |
From perl you want to know the size of a file.
In perl you can use file test operators. The operator that will provide you with the size of the file is -s:
#!/usr/bin/perl
use strict;
use warnings;
my $filesize = -s "test.txt";
print "Size: $filesize\n";
exit 0;
The output of this might be (depending on the size of test.txt):
Size: 15
The module File::stat provides statistics on files:
#!/usr/bin/perl
use strict;
use warnings;
use File::stat;
my $filesize = stat("test.txt")->size;
print "Size: $filesize\n";
exit 0;
This would produce identical output to the previous example.
perldoc -f -X
perldoc File::stat