in reply to Re^5: Checking MD5 of files in directory with corresponding MD5 file type
in thread Checking MD5 of files in directory with corresponding MD5 file type
Hi Corion hope you're well, sorry I've not got back to you, I had to take a week off work due to family reasons. I'm back at the code today and am trying to follow the steps and suggestions you indicated before. So far, so good, but I have a problem with "blindly" opening the .md5 equivalent of the file I pass to the 'routine' subroutine
The code I have so far is (with exclusion of the other subroutines which I know work fine):
use strict; use warnings; use Digest::MD5; my $sourcedirectory = '//path/to/directory'; &main(); sub main { # creating file array my @files = &getfiles($sourcedirectory); # removal of the two directory structures which form the start of +the file array my $rmdir = shift (@files); my $rmdir2 = shift (@files); # capture of a count of the number of files remaining in the array my $filecount = @files; # check to see if there are no files, if none, exit script if ($filecount == 0) { print "\nNo files to process\n\n"; exit; } # where there are files, the routine subroutine is called for each + item individually (except for md5 file types) else { foreach my $item (@files) { next if $item =~ /.md5/; my $filepath = "$sourcedirectory/$item"; &routine($filepath, $item); } } } sub routine { # identify filepath and name as parameters passed to routine my $file = shift; my $name = shift; # open file, set to binary mode, close and process MD5 open my $fh, '<', $file or die "Can't open file: $!"; binmode ($fh); my $md5tocompare = &processmd5($fh); close $fh or die "Can't close file successfully: $!"; # check file.md5 existence and open and read to memory open my $fh2, '<', "$file.md5" or next; my $originalmd5 = <$fh2>; close $fh2 or die "Can't close file successfully: $!"; # check parity print "MD5 is $md5tocompare against orignal MD5 of $originalmd5\n" +; } ...
Every time I run this code, the script exits the at the 'next' statement upon attempting to open the "$file.md5" handle. Do you have any idea what I am doing wrong here? I know the MD5 file exists so it is probably syntax or the way I am trying to get a handle on the file, but I'm at a loss at the moment. Tried it bare, with single and double quotes etc :)
Any indicator you could provide would be appreciated
Many thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Checking MD5 of files in directory with corresponding MD5 file type
by Corion (Patriarch) on Jan 06, 2017 at 11:40 UTC | |
|
Re^7: Checking MD5 of files in directory with corresponding MD5 file type
by deedo (Novice) on Jan 06, 2017 at 11:29 UTC |