On Jun 11, 2013, at 9:44 PM, lee wrote: > Hi, > > 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?
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: cpan install Digest::CPAN The first time you run cpan, it will need to configure your environment. You may have to use 'sudo cpan' for the first command. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/