Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Is there a Perl version of UNIX "cmp" ?

by samtregar (Abbot)
on Feb 06, 2009 at 19:22 UTC ( #741987=note: print w/replies, xml ) Need Help??

in reply to Is there a Perl version of UNIX "cmp" ?

I agree that there's no compelling reason not to just call it from system() but if you did need it in Perl code it'd be a fun challenge. I think I'd do it by reading in chunks from each file and doing an MD5 on each chunk with Digest::MD5. Compare the MD5s and if they're different then you've got a difference. Oh, and start by comparing file sizes!


  • Comment on Re: Is there a Perl version of UNIX "cmp" ?

Replies are listed 'Best First'.
Re^2: Is there a Perl version of UNIX "cmp" ?
by merlyn (Sage) on Feb 06, 2009 at 23:11 UTC
    Uh, you start with block A and block B in memory. Not sure how you think computing the MD5 on each block (hitting every byte, doing math) is going to be any faster than just comparing the blocks themselves (comparing byte by byte, but stopping on first difference). Bizarre.
      MD5 is magic! Ok, good point.


        MD5 is not a general solution to compare two strings, but it can be useful to compare a string against many others. That's not needed here.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2020-07-08 15:23 GMT
Find Nodes?
    Voting Booth?

    No recent polls found