in reply to MD 5 hash comparison/checker
Why would a user want to do that?
I was wondering if it's possible to tell the user if there are differences or if they are the same
Look up the unix/linux "cmp" and "diff" commands. They were designed to do just that.
Here's the code...
I'm always baffled when I see these SoPW posts where the code is set up to ask questions of the user and read the user's responses from STDIN. It's almost always true that the information being asked for could/should be provided as command line args, so that the script gets them from @ARGV instead of reading them from STDIN.
Once you understand that every CLI shell worth using keeps a command history, and interprets the "up-arrow" key as "go back to the previous command line", you'll see how much nicer it is to use command-line args to convey run-time instructions to your script (e.g. names of files, optional parameters, etc). If you are using a shell that doesn't support command history and recall, get another shell.
As for the actual task that you're trying to accomplish: if it involves looking for duplicate file content, build a table that has path/filename, file_byte_count and file_md5 for the files of interest, sort the table on md5 and file size, and just do a byte-for-byte comparison (à la 'diff', 'cmp' or ikegami's code snippet) on the files that have identical sizes and md5s. (It's entirely possible that two files of the same size may have the same md5 sig, despite having different content.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: MD 5 hash comparison/checker
by daggy (Novice) on May 07, 2010 at 03:12 UTC | |
by ikegami (Patriarch) on May 07, 2010 at 23:49 UTC | |
by Anonymous Monk on May 08, 2010 at 07:21 UTC |