Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comparing MDB files.

by vinoth.ree (Monsignor)
on Jul 14, 2019 at 18:00 UTC ( #11102837=perlquestion: print w/replies, xml ) Need Help??

vinoth.ree has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I want to compare two .mdb(Microsoft access files), to find are there any changes done on the files, for that I just wrote the below function.

sub compare { my $pre_version =shift; my $new_version =shift; print("previous version: $pre_version\n"); print("new version : $new_version\n"); my $pre = Digest::MD5->new; open (PRE, "$pre_version"); $pre->addfile(*PRE); close(PRE); my $pre_digest = $pre->hexdigest; #print "pre digest=$pre_digest\n"; my $new = Digest::MD5->new; open (NEW, "$new_version"); $new->addfile(*NEW); close(NEW); my $new_digest = $new->hexdigest; #print "new digest=$new_digest\n"; if ($pre_digest eq $new_digest) { print("Equal\n"); return 0; } else { print("Not Equal\n"); return 1; } }
Update: Variable names modified.

Even thought there are no changes between two MDB files I am always getting "Not Equal".

pre_version of the MDB file downloaded from git and new_version was a local copy. before pushing to the git repository I want to make sure there are some difference. If the are no difference I need to block the push.


All is well. I learn by answering your questions...

Replies are listed 'Best First'.
Re: Comparing MDB files.
by haukex (Bishop) on Jul 14, 2019 at 18:08 UTC
    my $pre = Digest::MD5->new;
    open (PRE, "$pre_version");
    $new->addfile(*PRE);
    close(PRE);
    my $pre_digest = $pre->hexdigest;
    my $new = Digest::MD5->new;
    open (NEW, "$new_version");
    $co->addfile(*NEW);
    close(NEW);
    my $new_digest = $co->hexdigest;
    if ($pew_digest eq $new_digest) {
    

    Use strict and warnings. You never add any data to either of the Digest::MD5 objects, which means you'd be comparing the MD5 sums of zero bytes to each other, which should always be true, if you were comparing the correct variables.

    before pushing to the git repository I want to make sure there are some difference. If the are no difference I need to block the push.

    Why? If it's about saving space, it's not necessary, as git should deduplicate data automatically.

    Update: Also, please read "open" Best Practices, and either use the open mode '<:raw' or binmode your filehandles, as is mentioned in the Digest::MD5 docs. Also improved formatting of code block.

      ... git should deduplicate data automatically
      It indeed does
      Git doesn’t think of or store its data this way. Instead, Git thinks of its data more like a set of snapshots of a mini filesystem. Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. To be efficient, if files have not changed, Git doesn’t store the file again—just a link to the previous identical file it has already stored.


      holli

      You can lead your users to water, but alas, you cannot drown them.
      Hi,

      Sorry, I had different variable name, for people understanding I changed the variable names while posting the questing. I just updated them.


      All is well. I learn by answering your questions...

        Thanks for informing us about your update, but how does this code even run? $co->hexdigest should either not be compiling, or be dieing with "Can't call method "hexdigest" on an undefined value" or "Can't locate object method "hexdigest" via package ...".

        Update: Please see Short, Self-Contained, Correct Example. Unfortunately, we can't diagnose the issues you might be having with your code if you don't provide something representative that we can run, and especially not if the code you post suffers from issues that don't even exist in the original code. Also made second sentence more accurate.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11102837]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2020-09-19 02:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I don’t succeed, I …










    Results (114 votes). Check out past polls.

    Notices?