top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

sha-2 sum of files in perl?

0 votes
399 views

what I'm trying to do is create a list of sha-2 sums of files the names of which are stored in a file. The purpose is to verify from time to time whether any of the listed files have been modified or not in the
meantime.

So I can read the list of file names; what I don't understand is what the most efficient way would be to create a sha-2 sum for a file.

It doesn't even need to be sha-2 since there are no security issues involved. The only purpose is to figure out reliably if any of the files on the list have been modified or not. I don't want to go by file modification dates because that isn't entirely reliable.

I've been googling for examples of how to create a sha-2 sum of a file in perl without success. What I'm looking for is something like:

 $hash = create_sha2_sum( $filename);

Do you know of any examples I could look at? Or is there a better way to figure out if a file has been modified?

posted Jun 12, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

The first thing to do would be to check the file size. If the file size has changed, then the file has been modified. So you will want to save the file size.

If the files sizes are the same, then you can compare some sort of digest e.g. SHA. I haven't used any, so I cannot advise.

A good place to look for Perl modules is the Comprehensive Perl Archive Network (CPAN). Go to http://search.cpan.org and enter SHA into the search box. This will give you modules such as Digest::SHA, which seems to do what you want.

Next, install the module on your system. On a Unix-like system or one that supports command-line input, you would do:

answer Jun 12, 2013 by anonymous
+1 vote

Have you considered Digest?

http://perldoc.perl.org/Digest.html

answer Jun 12, 2013 by anonymous
Similar Questions
+1 vote

I'm in the process of moving certain files of the SurfShop script into a sub-directory to clean up the main directory and would like to know the best way for the script to find these files.

I was using this method:

use FindBin qw($Bin);
use lib "$Bin/../ss_files";

which worked for me, but I read somewhere that FindBin can break in certain situations. So I tried the following:

use lib "ss_files";

This also works, but iirc, I read that it won't work across all platforms, is that correct? Is one of these methods better than the other, or is there another way that I haven't found yet?

+1 vote

I'm looking for introductory to advanced examples of RESTful programming in Perl preferably with some good explanations and best practices.

+1 vote

I am running a script under perl -d and want to break execution at line 243 in this case. perl -d scriptname loads the script in to the debugger and b 243 sets the break point. c then Enter starts the program which runs until it reaches the desired line at which point it stops. All I want to do is get it to loop multiple times through this point and then stop.

This is similar to the behavior of gdb where you could tell it to stop after, say, 250 passes through the break point.

...