filesize

How do I get the size of a file in Perl?

From perl you want to know the size of a file.

Solution 1: file test operators

In perl you can use file test operators. The operator that will provide you with the size of the file is -s:

The output of this might be (depending on the size of test.txt):

Solution 2: The OO way

The module File::stat provides statistics on files:

This would produce identical output to the previous example.

See also

Scroll to Top