Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Comparing MDB files.

by haukex (Archbishop)
on Jul 14, 2019 at 18:08 UTC ( [id://11102838]=note: print w/replies, xml ) Need Help??


in reply to Comparing MDB files.

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.

Replies are listed 'Best First'.
Re^2: Comparing MDB files.
by holli (Abbot) on Jul 14, 2019 at 18:43 UTC
    ... 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.
Re^2: Comparing MDB files.
by vinoth.ree (Monsignor) on Jul 14, 2019 at 18:16 UTC
    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.

        Hi haukex

        I got your point. Actually I thought I was missing something in this compare function, while calculating md5 checksum. That is why I posted that function alone. Here is the full code.

        use strict; use warnings; use Digest::MD5; 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; } } compare($oldfile_path, $newfile_path);

        Update:variable name updated from $co to $new


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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-16 17:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found