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

Sure , in perl power tools, cmp, or File::Compare
  • 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 Amphiaraus (Beadle) on Feb 06, 2009 at 21:39 UTC
    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?
      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 :-)

      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.