I have an MD5 hash perl tool. It currently allows the user to input two file paths and it then displays the md5 hash of each file.

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.)


In reply to Re: MD 5 hash comparison/checker by graff
in thread MD 5 hash comparison/checker by daggy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.