Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: -e stransgeosities

by pvaldes (Chaplain)
on Apr 20, 2012 at 15:42 UTC ( [id://966212]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://966212]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found