hold its content in memory

Assuming the *.md5files contain just the value (single line ?) then consider reading them all first and use a hash to store the results for comparison later, for example

#!perl # test.pl use strict; use warnings; use Cwd; use Digest::MD5; use Data::Dump 'pp'; my $sourcedirectory = cwd(); # '//path/to/directory' # create test file with md5 value open my $io_handle,'<','test.pl' or die "$!"; my $md5 = Digest::MD5->new; $md5->addfile($io_handle); close $io_handle; open OUT,'>','test.md5' or die "$!"; print OUT $md5->hexdigest; close OUT; # read md5 values into a hash my $md5values = get_md5values($sourcedirectory); pp $md5values; sub get_md5values { my $sourcefiles = shift; opendir(DIR, $sourcefiles) or die "Can't open directory, $!"; my @md5_files = grep /\.md5$/,readdir(DIR); closedir(DIR); my %md5 = (); for my $filename (@md5_files){ my $count = 0; open MD5,'<',$filename or die "$!"; while (<MD5>){ chomp; $md5{$filename} .= $_; ++$count; } close MD5; print "$count lines read from $filename\n"; } return \%md5; }
poj

In reply to Re^5: Checking MD5 of files in directory with corresponding MD5 file type by poj
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.