Why not just use a hash as a simple lookup table?

This refactored version of your script prints a tab-separated list of all the files specified as arguments on the command line. The report includes a Boolean column indicating if each file's MD5 digest matches one of the digests in the lookup table:  Yes or No.

#!perl use strict; use warnings; use autodie qw( open close ); use Digest::MD5; use English qw( -no_match_vars ); use File::Glob qw( bsd_glob ); @ARGV or die "Usage: perl $PROGRAM_NAME file ...\n"; @ARGV = map { bsd_glob($ARG) } @ARGV; local $OUTPUT_FIELD_SEPARATOR = "\t"; local $OUTPUT_RECORD_SEPARATOR = "\n"; my %md5_digests_table = map { $ARG => 1 } qw( d41d8cd98f00b204e9800998ecf8427e d6721344ed0cdc2e8a054a68b7ebc365 cee8eb94fd83f8d534bc44bf136ebaa0 ); for my $file (@ARGV) { open my $fh, '<', $file; binmode($fh); my $md5 = Digest::MD5->new()->addfile($fh)->hexdigest(); close $fh; my $match = exists $md5_digests_table{$md5} ? 'Yes' : 'No'; print $file, $md5, $match; } exit 0;

In reply to Re^4: compare md5 from file against entire@md5 array by Jim
in thread compare md5 from file against entire@md5 array by james289o9

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.