Hello, Hoping to get an idea as to the best way to approach the problem that I am having. I am trying to search an array for a list of strings which I can keep in an array or as individual variables. I need all SEARCH strings to EXIST/MATCH within the array that I am searching against and only print if the entire list or search strings are found. For example this is what I tried with no luck.
#!/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"; } } }
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.

In reply to 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.