September 2002
Intermediate to advanced
496 pages
10h
English
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>); ...