⭐ in reply to How do I portably determine if two filenames refer to the same file?
For POSIX systems, the first two values in the list returned by Perl's stat builtin provide a solution. These are the "device" and "inode" numbers for the file and, taken as a pair, uniquely identify a file.
# return true if both names are for the same file sub check_same_file_under_posix { my ($file_a, $file_b) = @_; my ($dev_a, $ino_a, @other_a) = stat($file_a); my ($dev_b, $ino_b, @other_b) = stat($file_b); if (($dev_a == $dev_b) && ($ino_a == $ino_b)) { return 1 } else { return 0 } }
|
|---|