[Wellington-pm] perl -f check failed

Richard Hector richard at walnut.gen.nz
Wed Jul 21 04:58:10 PDT 2010


On Wed, 2010-07-21 at 18:07 +1000, Jacinta Richardson wrote:

> * Symlinks will return true for -e and true for -f (which surprised me)
> 
> % ln -s foo bar
> % perl -e 'print "exists\n" if -e "bar"; print "plain\n" if -f "bar"';
> exists
> plain

Depends on what the target is - a symlink to a device, for example, is
not a plain file:

$ ln -s /dev/tty0 bar
$ perl -e 'print "exists\n" if -e "bar"; print "plain\n" if -f "bar"'
exists

>  If you want to test that a file both exists and is a plain file, 
> then you need to use both tests:
> 
> 	if(-e $file && -f _)

Hmm - are there any cases where a file _doesn't_ exist, but is a plain
file nonetheless? I'd have thought -f alone was fine for that.

Richard




More information about the Wellington-pm mailing list