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.
Operator | Meaning |
---|---|
-e | File exists. |
-z | File has zero size. |
-s | File has nonzero size (returns size). |
-f | File is a plain file. |
-d | File is a directory. |
-T | File is a text file. |
-B | File is a binary file (opposite of –T). |
-M | Age 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.