in reply to Cwd's abs_path not working with filetests?

abs_path will still only work relative to the current working directory. Which means that the results for relative paths will also be relative to your current working directory and not $path.

Replies are listed 'Best First'.
Re^2: Cwd's abs_path not working with filetests?
by Anonymous Monk on Nov 26, 2013 at 10:42 UTC

    Thx for the fast reply. If I got this right, it means to filetest a random path/file it's necessary to:

    1. extract the path and chdir into the specified directory

    2. perform the filetest

    3. chdir back to the cwd

    I do not want to lean too far out of the window, but isn't this kinda defeating a purpose of abs_path()?

    Cheers, LeJosh

      but isn't this kinda defeating a purpose of abs_path()?

      I think you've misunderstood the purpose of abs_path(). It resolves any symlinks along the given path and returns the canonicalized "absolute" path with all symlinks removed (see also "man realpath").

      If you give it a relative path, it assumes it's relative to the CWD (as usual), not to whatever readdir() is currently processing...

        Yeah, you're right. I thought abs_path is an easy way out for arbitrary filetesting. Well, I was wrong.

      I do not want to lean too far out of the window, but isn't this kinda defeating a purpose of abs_path()?

      Do you know what readdir does? The mistake you're making is explained in readdir documentation, so read perldoc readdir or simply use Path::Tiny and be done with it