Chinaunix首页 | 论坛 | 博客
  • 博客访问: 858932
  • 博文数量: 253
  • 博客积分: 6891
  • 博客等级: 准将
  • 技术积分: 2502
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-03 11:01
文章分类

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-10-14 10:55:13

-r File or directory is readable by this (effective) user or group
-w File or directory is writable by this (effective) user or group
-x File or directory is executable by this (effective) user or group
-o File or directory is owned by this (effective) user
-R File or directory is readable by this real user or group
-W File or directory is writable by this real user or group
-X File or directory is executable by this real user or group
-O File or directory is owned by this real user
-e File or directory name exists
-z File exists and has zero size (always false for directories)
-s File or directory exists and has nonzero size (the value is the size in bytes)
-f Entry is a plain file
-d Entry is a directory
-l Entry is a symbolic link
-S Entry is a socket
-p Entry is a named pipe (a “fifo”)
-b Entry is a block-special file (like a mountable disk)
-c Entry is a character-special file (like an I/O device)
-u File or directory is setuid
-g File or directory is setgid
-k File or directory has the sticky bit set
-t The filehandle is a TTY (as reported by the isatty() system function; filenames can’t be tested by this test)
-T File looks like a “text” file
-B File looks like a “binary” file
-M Modification age (measured in days)
-A Access age (measured in days)
-C Inode-modification age (measured in days)

Perl has a special shortcut to help us not do so much work. The virtual filehandle _
(just the underscore) uses the information from the last file lookup that a file test op-
erator performed. Perl only has to look up the file information once now:
if( -r $file and -w _ ) {
    ... }

Stacked File Test Operators
Previous to Perl 5.10, if we wanted to test several file attributes at the same time, we
had to test them individually, even if using the _ filehandle to save ourselves some work.
Suppose we wanted to test whether a file was readable and writable at the same time.
We’d have to test whether it’s readable and then also test whether it’s writable:
if( -r $file and -w _ ) {
    print "The file is both readable and writable!\n";
    }
It’s much easier to do this all at once. Perl 5.10 lets us “stack” our file test operators by
lining them all up before the filename:
use 5.010;
if( -w -r $file ) {
    print "The file is both readable and writable!\n";
    }
阅读(424) | 评论(0) | 转发(0) |
0

上一篇:DBI module

下一篇:The stat and lstat Functions

给主人留下些什么吧!~~