Here's a solution that allows you to change either the full (@files) or required (@need) lists of files. The order you supply the elements to either list doesn't matter: the code handles that for you. Also, filenames are likely to contain characters outside of the [A-Z] range (e.g. a.txt, b.pl, c.png, etc.): I've wrapped these in \Q...\E to avoid interference with the regex.

use strict; use warnings; my @files = qw{ABC DEF GHI JKL MNO PQR STU}; my @need = qw{MNO ABC GHI}; my $need_re = join q{\s.*?} => map { q{\b} . qq{\Q$_\E} . q{\b} } sort + @need; if (join(q{ } => map { qq{\Q$_\E} } sort @files) =~ /$need_re/) { print qq{OK\n}; } else { print qq{NOT OK\n}; }

-- Ken


In reply to Re: Check Array Elements by kcott
in thread Check Array Elements by mmittiga17

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.