- Joined
- Oct 8, 2001
- Location
- Redmond, WA
- Thread Starter
- #321
Why not just test whether the file exists. You can test other properties with other tests, some of which are here.
Alternately, you can do any number of things based on the return value of open():
The Camel book (aka "Programming Perl") only refers to try blocks once while mentioning that Java has them, so it's safe to say that they don't exist in Perl 5.
Code:
#!/usr/bin/perl -w
#user frankfurter doesn't exist, so "/home/frankfurter" doesn't exist either
$file="/home/frankfurter/.mksig/mksig.conf";
if ( -f $file ) {
print "found file\n";
} else {
print "file doesn't seem to exist\n";
}
Alternately, you can do any number of things based on the return value of open():
Code:
#!/usr/bin/perl -w
$file="/home/frankfurter/.mksig/mksig.conf";
if ( open FILE, $file ) {
print "found file\n";
close FILE
} else {
print "file couldn't be opened\n";
print "the error was: $!\n";
}
The Camel book (aka "Programming Perl") only refers to try blocks once while mentioning that Java has them, so it's safe to say that they don't exist in Perl 5.
Last edited: