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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |