in reply to Testing if two paths point to the same file.

Cwd has got a method for it :-)
perl -MTest::More=no_plan -MCwd=realpath -e ' is (realpath("/etc/passwd"), realpath("/etc/../etc/passwd")) ' ok 1 1..1

print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});

Replies are listed 'Best First'.
Re^2: Testing if two paths point to the same file.
by MidLifeXis (Monsignor) on Jan 30, 2009 at 15:19 UTC

    I don't think this is what the OP is asking for.

    Under *nix, if I do ln foo.txt bar.txt, then I have two directory entries pointing to the same physical file. The inode for this file is identical. Two different directory entries, one physical file.

    Your example checks to see if the ending of the files passes through the same part of the directory tree. One physical file, one directory entry (at least for the final part of the path).

    Now, if realpath would identify that foo.txt and bar.txt point to the same inode, then it would be identical. As it stands, it is not.

    Still a useful solution, however, to a different problem.

    --MidLifeXis

Re^2: Testing if two paths point to the same file.
by lostjimmy (Chaplain) on Jan 30, 2009 at 15:12 UTC
    Will that work for hard links?
      Technically, ".." is a hard link. But in general, no.
      $ touch foo $ ln foo bar $ perl -MTest::More=no_plan -MCwd=realpath -e ' is(realpath($ARGV[0]), realpath($ARGV[1])) ' foo bar not ok 1 # Failed test at -e line 2. # got: '/home/eric/foo' # expected: '/home/eric/bar' 1..1 # Looks like you failed 1 test of 1.