... with filenames that are based on those numbers.

If the derivation of filename from ID is predictable, it might be more efficient to create a hash of filenames from the IDs then use grep to select appropriate files from your @files array rather than keep looping over files and IDs.

use strict; use warnings; my @IDs = qw{ pj7023 ge4872 dr90324 jc824 }; my @files = qw{ XYZ_dr90324.txt XYZ_at728.txt XYZ_jc824.txt XYZ_uf72082.txt XYZ_tc43.txt XYZ_pj7023.txt XYZ_yj82195.txt XYZ_fw607.txt }; my %IDnames = map { my $key = q{XYZ_} . $_ . q{.txt}; $key => 1 } @IDs; my @selectedFiles = grep exists $IDnames{ $_ }, @files; print qq{$_\n} for @selectedFiles;

The output.

XYZ_dr90324.txt XYZ_jc824.txt XYZ_pj7023.txt

It might be that the filename can't be confidently derived from the ID and this method will not work but I thought I'd post the idea just in case.

Cheers,

JohnGG


In reply to Re: Check If 2 Arrays Match by johngg
in thread Check If 2 Arrays Match by facedag

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.