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


In reply to Re^6: Checking MD5 of files in directory with corresponding MD5 file type by deedo
in thread Checking MD5 of files in directory with corresponding MD5 file type by deedo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.