http://www.perlmonks.org?node_id=966212


in reply to -e stransgeosities

I was attempting to see if the same file existed in two directories. So I set up...

No, this is not the way. Two files can have the same name in different directories and have very different contents. The same file can be saved also with a different name.

You could install and use fdupes

print `fdupes -S /path/to/myfirstdir/ /path/to/myotherdir/`;

Or read this node: Find duplicate files.

The idea is to compute the md5sum of your target and look for a file with the same md5sum, i.e. with the Digest::md5 module.

Replies are listed 'Best First'.
Re^2: -e stransgeosities
by misterperl (Pilgrim) on Apr 23, 2012 at 13:44 UTC
    thanks for the replies. I tried it with both relative and absolute paths- same result. And As I said, I cut and pasted the directories from the debugger and *ls'ed* them and they are fine ;so there appears to be no oddball characters.
    
    I should have been more accurate and said I was looking for duplicate file NAMES, not contents. I don't really care what's in them. 
    
    Basically the questions are 
    
    (a) why does -e valid_file_path return undef, and 
    
    (b) why does (defined $a && $a) return TRUE when $a eq undef?
    
    

      Please, instead of showing excerpts from debugger sessions together with some narrative, write and show a short program that replicates the steps you did. This makes it far more clear what you did and what results you get.

      A rough start could be:

      #!perl -w use strict; my $d1 = '/this/file'; my $d2 = '/that/file'; for ($d1, $d2) { print "[$_] " . (-e $_ ? "exists" : "does not exist") . "\n"; }; if (...) { ... }; # Show the contents of the directories in question system("find /this /that");

      Ad a) Because the file path is not valid. I bet there is some whitespace character in the variable.

      Ad b) So $a is not undef, it just eq undef. Waitasecond ... an empty string is defined, yet equals to undef. Or maybe I should say undef gets turned into an empty string in a string context?

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.