Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by Amphiaraus (Beadle)
on Feb 06, 2009 at 21:39 UTC ( [id://742012]=note: print w/replies, xml ) Need Help??


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

Does anyone know if File::Compare's compare() function is "large-file-aware"? i.e. does it reliably return a correct boolean value when comparing large non-human-readable files?
  • Comment on Re^2: Is there a Perl version of UNIX "cmp" ?

Replies are listed 'Best First'.
Re^3: Is there a Perl version of UNIX "cmp" ?
by runrig (Abbot) on Feb 06, 2009 at 22:09 UTC
    If perl was compiled with the USE_LARGE_FILES flag (which it likely was if your OS handles large files), it will handle large files (see "perl -V" for that info). Still, "cmp" is likely going to be much faster than File::Compare. The only way to tell is to try both on your large files. Coding practices are fine, but they should be guidelines, not absolutes.

    Update: quick benchmark on two identical 1GB files on HP-UX - 13.5 secs (cmp) vs. 17.5 seconds (File::Compare). "much faster" is relative it seems :-)

Re^3: Is there a Perl version of UNIX "cmp" ?
by kwaping (Priest) on Feb 06, 2009 at 23:38 UTC
    Looking at the source for File::Compare, there is an undocumented third input that is used as the read buffer size. A default is used if that third argument is not provided, which is the size of the first file (-s FROM). If that file - or the third argument - is larger than 1024 * 1024 * 2, that number (2mb) is used as the buffer size.

    Basically, it reads the file in chunks up to 2mb, so it should be able to handle files of virtually any size given enough time.

    ---
    It's all fine and dandy until someone has to look at the code.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-26 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found