Hi Perl Pros
This is my first call for help
I am a totally new, self teaching, Perl hopeful
If my approach to this script is simply wrong, please let me know as it
will help my learning!
The script aims to:
1) Read in a directory either from the command line, or from a default path
2) Produce a hash for future checksum
3) Write this (hex digest) to a separate file, in a sub directory of the
parent, which has the same name and a .md5 extension
4) Check the original file for its size
5) Add this data to the newly created file on a new line (in bytes)
I have a script that will do most of this, except for analysing the file
size - I think that the file size being analysed may be the md5 object
result as the same value is printed to each file
I am running out of ideas and would appreciate any help you could give!
I have tried using File::stat::OO and File::stat - but to no avail - I
could be using them incorrectly!
Many thanks in advance...
Jon.
Here are some details:
System:
Mac OSX 10.7.2
Perl version 5.12
Script:
#!/usr/bin/perl
# md5-test-3.plx
use warnings;
use strict;
use Digest::MD5;
my $filesize = 0;
my $dir = shift || '/Users/jonharris/Documents/begperl';
opendir (DH, $dir) or die "Couldn't open directory: $!";
my $md5 = Digest::MD5->new;
while ($_ = readdir(DH)) {
$md5->add($_);
$filesize = (stat(DH))[7];
#### Is it necessary to put the following into a new loop?
foreach ($_) {
open FH, ">> /Users/jonharris/Documents/begperl/md5/$_.md5" or die $!;
binmode(FH);
print FH $md5->hexdigest, "\n", $filesize;
}
close FH;
}
close DH;
print "\n$dir\n\n";
#######