in reply to error handling using symlink

See perldoc for symlink

Replies are listed 'Best First'.
Re^2: error handling using symlink
by cheekuperl (Monk) on Jun 18, 2012 at 08:11 UTC
    Perhaps I interpreted it(i.e. your question) wrong the first time.
    If the original file is oldfile and the link you are creating is newfile, the call would be:
    $stat=symlink("oldfile","newfile");
    This is known to us.
    newfile is created even if oldfile does not exist. It is not an error. Is that what you wanted to ask?
    You might verify if oldfile exists using -e test.
    if(-e $oldfile) { #create symlink } else { #Report $oldfile doesnt exist!
    }

      cheekuperl,

      you're right now. Even though old file doesn't exists, it is creating the symlink which I don't want it. Yes, we can use filetest operations before creating the symlink.

        To follow up on cheekuperl's post, a symlink's target does not need to exist in order to be successfully created. Be aware it is possible that the original file might be changed, deleted, renamed, or otherwise altered between your check and the creation of the symlink, or even any time after you create the symlink. -r (see -X) and company act on the target of the symlink, so that might be another check that you may want to use.

        Symlinks are nice, but just make certain that you are not thinking that they do more than they are designed to do.

        --MidLifeXis