I noticed strange behavior of the -d
flag to check if a file is a directory and if the directory exists. It behaves differently when using ~/my_dir
as my path.
The following code will return false, even though the directory my_dir
exists, but if I'll change it to a full path like /home/ricky/my_dir
, then the if
statement will return true.
#!/usr/bin/perl -w
#
use strict;
if ( -d "~/my_dir") {
print "Found \n";
}
else {
print "Not found \n";
}
What's the difference?