Hello folks, am new bee to perl and while writing a code i got stuck need some help. I want to search a bunch of strings which are stored in an array , and search those strings inside files of a specific directory. but am not able to do it , here is my code may be if u can help thanks in advance . . .
#!/usr/bin/perl my $file_name = $ARGV[0]; # parsing filename the elements of thi +s file will be sotred in @store array my $dir = $ARGV[1]; # parsing the directory in which the c +ontents of array will be searched in each file of this directory open (F, "$file_name") || die ("Could not open $file_name!"); # open +ing file while($line = <F>) { print "pushwala while"; push (@store, $line); #storing contents of file to @stor +e array } print "@store"; # printing contents of array close (F); # closing file opendir (DIR, $dir) or die $!; # opening directory , of which we ha +ve to precess all files my @dir = readdir DIR; foreach my $filename (@dir) { # print "$filename\n"; open (F, "$dir/$filename") || die ("Could not open $filename"); # o +pening Each file of the directory foreach (@store) { print "$_"; # printing contents of @store array , F +IXME here is the problem this prints 3 times all the contents of @sto +re array while($line = <F>) # cheking each line of files in th +e directory { print "$line"; # check if ($line =~ /$_/) # pattern matching between co +ntens of array and each line of files in directory { chomp ($_); #last if; print "testcase name:$_\n"; + # print "file includeing testcase:$filename\n"; + # if pattern is found printing it print "line:$line\n"; + # break; # breaking while loop } else { chomp ($_); print "$_:not found\n\n"; + # if pattern is not found break; # breaking while loop } } } }
# problem with this script is, i want to check all the lines of all the files included in the diretory and if the pattern is not found then only print that string not found, # but instead it is printing on every line string not found . and if the string is found i.e matched in a file the it should discontinue its search . Please help me folks

In reply to Search strings stored in array into files of a directory by tejas1991

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.