use strict; use warnings; #Data contained in the TXT File ARRAY my @dataArray = ("12/12-08:01:22.360401 *** [945850] pr0", "12/13-08:03:22.420449 *** [948851] pr1", "12/16-08:04:22.439726 *** [948852] pr0", "12/17-08:10:22.440649 *** [948853] pr1", "12/17-08:10:22.444688 *** [948854] pr1", "12/17-08:10:22.512471 *** [948855] pr2", "12/17-08:10:22.512471 *** [948856] pr0", "12/17-08:10:22.527738 *** [948857] pr1", "12/17-08:10:22.527888 *** [948858] pr3", "12/17-08:10:22.527898 *** [948859] pr2", "12/17-08:10:22.527999 *** [948860] pr2", "12/17-08:10:22.528999 *** [948861] pr2", "12/17-08:10:22.529999 *** [948862] pr2" ); #Search strings that must much - ARRAY form. my @arrayOfSearchStrings = map { "[$_]" } 945850 .. 945852; my %found; for (@dataArray) { for my $pat (@arrayOfSearchStrings) { $found{$pat}++ if /\Q$pat/; } } if (@arrayOfSearchStrings == (keys %found)) { print "Found ALL SEARCH STRINGS required in ARRAY\n"; } else { print "Did not find all needed search strings\n"; } __END__ Did not find all needed search strings
Update: This may be faster since it stops looking though the dataArray as soon as it finds all your search strings:
#Search strings that must much - ARRAY form. my @arrayOfSearchStrings = map { "[$_]" } 945850 .. 945852; my %searchStrings = map { $_ => 1 } @arrayOfSearchStrings; OUTER: for (@dataArray) { for my $pat (keys %searchStrings) { if (/\Q$pat/) { delete $searchStrings{$pat}; last OUTER unless %searchStrings; } } } if (%searchStrings) { print "Did not find all needed search strings\n"; } else { print "Found ALL SEARCH STRINGS required in ARRAY\n"; }
In reply to Re: Search an array for array of strings
by toolic
in thread Search an array for array of strings
by perlnewbie9292
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |