For example: I only want to **print "Found ALL SEARCH STRINGS required in ARRAY\n";** if ALL three of my searchStrings [945850], [945851] and [945852] are in the @dataArray. If all of the search strings don't exist in the array print "Did not find all needed search strings\n"; Thanks for the help in advanced.#!/usr/bin/perl 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 match - non ARRAY my $searchString1 = "[945850]"; my $searchString2 = "[945851]"; my $searchString3 = "[945852]"; #Search strings that must much - ARRAY form. my @arrayOfSearchStrings = ( "[945850]", "[945851]", "[945852]", ); for my $data ( @dataArray ) { my @splits = split(/ /, $data); my @value = $splits[3]; for ( @value ) { if ( $_ == "$searchString1" && $_ == "$searchString2" +&& $_ == "$searchString3" ) { #if ( $_ =~ /[945850] && [945851] && [945852]/gm ) { #Print Found only if all the defined search #strings are found in the array, no match #if all do not exist within the array print "Found ALL SEARCH STRINGS required in AR +RAY\n"; } else { print "Did not find all needed search strings\ +n"; } } }
In reply to Search an array for array of strings by perlnewbie9292
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |