Jump to content

Check that file exists: Difference between revisions

(Python example; Re-Ordered languages)
Line 35:
==[[Perl]]==
[[Category:Perl]]
use File::Spec::Functions qw(catfile rootdir);
#!/usr/bin/perl
# here
sub isFileExists($) {
print -e 'input.txt';
my ($filename) = @_;
print -ed 'docs';
return -e $filename;
# root dir
}
print -e $FileSeperator.catfile rootdir, 'input.txt';
sub test($$) {
print -d catfile rootdir, 'docs';
my ($type, $filename) = @_;
print "The following " . $type . " called " . $filename .
(isFileExists($filename) ? " exists." : " not exists.");
}
my $FileSeperator = ($^O eq "MSWin32") ? "\\" : "/";
test("file", "input.txt");
test("file", $FileSeperator . "input.txt");
test("directory", "docs");
test("directory", $FileSeperator ."docs". $FileSeperator);
exit;
 
# Short version
my $FileSeperator = ($^O eq "MSWin32") ? "\\" : "/";
print -e 'input.txt';
print -e $FileSeperator.'input.txt';
print -e 'docs';
print -e $FileSeperator.'docs'.$FileSeperator;
 
==[[Pop11]]==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.