home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book Home Programming PerlSearch this book

32.24. File::stat

use File::stat;
$st = stat($file)      or die "Can't stat $file: $!";
if ($st->mode & 0111 and $st->nlink > 1)) {
    print "$file is executable with many links\n";
}

use File::stat ":FIELDS";
stat($file)            or die "Can't stat $file: $!";
if ($st_mode & 0111 and $st_nlink > 1) ) {
    print "$file is executable with many links\n";
}

@statinfo = CORE::stat($file);    # Access overridden built-in.
The File::stat module provides a method interface to Perl's built-in stat and lstat functions by replacing them with versions that return a File::stat object (or undef on failure). This object has methods that return the like-named structure field name from the traditional stat(2) syscall; namely, dev, ino, mode, nlink, uid, gid, rdev, size, atime, mtime, ctime, blksize, and blocks. You may also import the structure fields into your own namespace as regular variables using the ":FIELDS" import tag. (This still overrides your stat and lstat built-ins.) These fields show up as scalar variables named with a "st_" in front of the field name. That is, the $st_dev variable corresponds to the $st->dev method.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.