| Prev | Perl Notes |
Next |
It's often useful to know whether a file already exists, if it's readable, writeable, or executeable, and so on. You can combine the use of a conditional with a special set of codes that test for certain file states.
To check a files status:
chdir ("../../logs");
if ( -e $desired_file) {
open(LOG, $desired_file) || &ErrorMesage;
@log_lines = <LOG>;
close(LOG);
$n=1;
foreach $line (@log_lines) {
print "Line # $n is $line";
$n++;
}
} else {
print "Log does not exist.";
}
|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 0 | dev | device number of filesystem |
| 1 | ino | inode number |
| 2 | mode | file mode (type and permissions) |
| 3 | nlink | number of (hard) links to the file |
| 4 | uid | numeric user ID of file's owner |
| 5 | gid | numeric group ID of file's owner |
| 6 | rdev | the device identifier (special files only) |
| 7 | size | total size of file, in bytes |
| 8 | atime | last access time since the epoch |
| 9 | mtime | last modify time since the epoch |
| 10 | ctime | inode change time (NOT creation time!) since the epoch |
| 11 | blksize | preferred block size for file system I/O |
| 12 | blocks | actual number of blocks allocated |
| Prev | Home | Next |