Wednesday, March 11, 2009

How to tell if a file exists in perl?

#!/usr/bin/perl -w

$filename = '/path/to/your/file.doc';
if (-e $filename) {
print "File Exists!";
}

that the file does not exist - by using the unless conditional:

unless (-e $filename) {
print "File Doesn't Exist!";
}

1 comment:

Demon said...

Perl is the best scripting language for Text processing and handle regex. I have posted few articles related to those at my blog

http://icfun.blogspot.com/search/label/perl

Also Perl's Cpan has lots of support that I don't even need to think extra while developing project. I didn't find such help on other programming language except Java and .NET