File Inquiry Operators

There may be many occasions where a programming task depends upon the type of one or more files. For example, you may need to know whether a name represents a file or whether a file is a directory. Perl has several operators that can help you toward these tasks. Table 3-3 shows some of these operators.

Table 3-3. Some File Inquiry Operators
OperatorMeaning
-eFile exists.
-zFile has zero size.
-sFile has nonzero size (returns size).
-fFile is a plain file.
-dFile is a directory.
-TFile is a text file.
-BFile is a binary file (opposite of –T).
-MAge of file in days

Here is a program that illustrates a few of these operators. See the folder FileStat.

 % type filestat.pl # # filestat.pl # print "Enter a filename "; chomp($fn = <STDIN>); ...

Get Programming PERL in the .NET Environment now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.