my $data= join("\t", map { /(\[\d*\])/ } @dataArray); my $notfound=0; foreach (@arrayOfSearchStrings) { if (not $data=~/\Q$_\E/) { $notfound=1; print "$_ not included\n"; last; } } print "All there\n" unless $notfound;

Basically I construct a string with all numbers in dataArray concatenated and then check for every number if it is in there. Might get a bit slow when @dataArray gets really huge. But then you could use a hash instead to store the dataArray numbers.

The \t is only there to prevent matching parts of two consecutive numbers. That can't happen as long as your numbers have brackets around them, but it is just a bit safer against future changes

\Q\E in the regular expression is there because brackets are special characters in regexes (that's why I also escape them in the first regex). And even when they are "hidden" in variables they need to be escaped and that's what \Q...\E does


In reply to Re: Search an array for array of strings by jethro
in thread Search an array for array of strings by perlnewbie9292

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.