if (-e "$ENV{MYHOME}/link") {
system("rm $ENV{MYHOME}/link");
}
This is the code being used to check if a symlink exists and remove it if it does.
I am tracking a bug where this code does not work. I have not been able to figure it out as of now, but what is happening is that this code is unable to remove the symlink, which results in a ‘File exists’ error down the line.
I wanted to check if there is some fundamental flaw with this technique? I also read about http://perldoc.perl.org/functions/unlink.html but would like to know if the current approach is not recommended due to some reason?
Just use:
If the unlink fails, it’ll say why. The
-lasks if the target is a link. The-easks if the file exists. If your link is to a non-existent file, it’ll return false, and your code would fail to remove the link.