in reply to Search an array for array of strings
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
|
|---|