Checking whether or not a file exists or not in Perl is a typical job that may be completed utilizing the -e operator. The -e operator returns true if the file exists and false if it doesn’t. For instance, the next code checks whether or not the file “myfile.txt” exists:
#!/usr/bin/perluse strict;use warnings;my $filename = 'myfile.txt';if (-e $filename) { print "The file $filename exists.n";} else { print "The file $filename doesn't exist.n";}The -e operator can be used to examine whether or not a listing exists. For instance, the next code checks whether or not the listing “mydirectory” exists: