-eを使います。use strict;
use warnings;
my $foo = 'hoge.txt';
if (-e $foo) {
print "$fooが存在します。\n";
} else {
print "$fooが存在しません。\n";
}
-eの場合、対象がディレクトリでも真が返ってくるので、ディレクトリと區別したい場合には-fを使います。
use strict;
use warnings;
my $bar = 'fuga.txt';
if (-f $bar) {
print "ファイル$barが存在します。\n";
} else {
print "ファイル$barが存在しません。\n";
}
use strict;
use warnings;
print "1: ファイルの存在を確認する。 -e \n";
my $file_all_type = 'a';
if (-e $file_all_type) {
print "'$file_all_type' は、存在します。\n";
}
else { print "'$file_all_type' は、存在しません。\n" }