Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by samtregar (Abbot)
on Feb 06, 2009 at 19:22 UTC ( [id://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!

-sam

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

      -sam

        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?
Username:
Password:

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

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

    No recent polls found