Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Handling Hash Comparison

by Errto (Vicar)
on Jul 23, 2005 at 04:04 UTC ( [id://477417]=note: print w/replies, xml ) Need Help??


in reply to Handling Hash Comparison

I see a couple of things here. First of all, not sure if this is a typo, but the way you're creating the hashes isn't right. The normal way to assign to a hash is

my %hash = ( key1 => value1, key2 => value2 ); ...
Using parentheses instead of braces is important because the parentheses denote a list of keys and values (which is what you want), whereas the braces denote a single scalar value that happens to be a hash reference (which is not what you want). Update: this paragraph is not applicable to the real code in the OP.

The other thing is that if your real data is like what you have here, you'll never get a match because the keys in %sdirdigest will never have exactly the same value as any key in %ddirrdigest because the root paths are different. Update: more precisely, the keys that go into both of your hashes are absolute paths. What you really want are the relative paths to the files, based on the respective starting directories. The way to fix this is to use $File::Find::dir instead of getcwd in your subs. Also it looks like you're trying to copy a file onto itself. Is that what you meant?

Replies are listed 'Best First'.
Re^2: Handling Hash Comparison
by omega_monk (Scribe) on Jul 23, 2005 at 04:09 UTC
    no, I posted my code in the readmore tags, in my original post. What happened is that initially I was only doing this in the dir that was specified at the command line, but later decided to add the ability to recurse dirs. my original code concatenated the dir onto the $key so that it copied appropriately, but when I added recursion, I could not longer copy the files in the same way, problem is I have no idea how best to proceed.

    Take a look at the rest of my code? Thanks.

    update: apologies, if that came off inappropriately, I was really just meaning to ask to have another look. Thanks for the pointer, I will take a look at File::Find:dir. One question, though. Does the logic make sense to get the filename for the second dir? I am probably just missing something obvious. I appreciate the help. Thanks again.
      Ok. I posted an update above - basically you can use $File::Find::dir instead of getcwd so that the relative path instead of the absolute path becomes the key. But now I'm unclear - I understand that if two files in corresponding relative paths have matching MD5 sums you want to do something, but I don't understand what that is. Right now what would happen is that you copy the file onto itself.
        exactly, and that is my issue, that I am not sure how I need to change the code to get the appropriate arguments to 'cp'.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2025-05-24 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.