Web Hosting Talk







View Full Version : Need perl help: function file is not exist


kapot
12-16-2003, 05:05 PM
I know that

if (-e 'file') { }

can be used to test the existance of a file. But how about the opposite? I need to test if a file is not exist. I tried below, but got failed.

#!/usr/bin/perl

my $dbfile = 'test.db';

if !(-e $dbfile) {
print "does not exists\n";
} else {
print "exists\n";
}

BMurtagh
12-16-2003, 06:58 PM
i'm not a perl programmer, although i do have perl in a nutshell that i looked at, couldn't you just do the following:

#!/usr/bin/perl

my $dbfile = 'test.db';

if (-e $dbfile) {
print "exists\n";
} else {
print "does not exists\n";
}

justsurge
12-16-2003, 09:30 PM
Originally posted by kapot
I know that

if (-e 'file') { }

can be used to test the existance of a file. But how about the opposite? I need to test if a file is not exist. I tried below, but got failed.

#!/usr/bin/perl

my $dbfile = 'test.db';

if !(-e $dbfile)


Like this:

if (!-e $dbfile)

Ej

YUPAPA
12-17-2003, 03:20 AM
better use -f cos -e can be dir also... if u have a dir that has the same name as $dbfile, it gives you a true value :fork: