On 6/15/07, sivasakthi <[EMAIL PROTECTED]> wrote:
> text mode: Line endings are translated to/from Perl's end-of-line > character "\n" to the host operating system's end-of-line character > (CRLF for DOS based machines, LF for UNIX based machines, etc.) > > binary mode (aka raw): No translations are made. Characters/bytes are > written directly to the file. > > encryption: A method of making data (hopeful) unreadable, but > recoverable, using an algorithm. The output can be either binary or > text depending on the algorithm. > > Do you want to compare two binary files to see if they have the same contents? Yes..i need to compare the contents of two binary files..
Alright, now that we understand what you want the question becomes why? Why use Perl? Is this part of some larger script? Is an approximation of equality good enough? Are we talking about equality or equivalence (every byte the same or contains the same records, but possibly in a different order)? How large are the files? Here is a simple script that will compare two or more files in a binary fashion, but it is no better than the standard Unix utilities. #!/usr/bin/perl use strict; use warnings; die "you must specify at least two files\n" unless @ARGV >= 2; my @files = map { open my $f, '<', $_ or die "could not open $_"; $f } @ARGV; $/ = \4096; my $chunk = 0; while (1) { my @chunks = grep { defined } map { scalar <$_> } @files; last if @chunks == 0; die "files don't match\n" unless @chunks == @files; my $first = shift @chunks; die "files don't match\n" if grep { $_ ne $first } @chunks; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/