Hello perl experts! I have a problem and i can`t figure out what to do. The problem sounds like: I have an array with a few words. I need to search in a few word files for every word in the array and if the word MATCH i will create a txt log. All good till now but i don`t know why if I have multiple words in the array, my code only find the first element of the array. :(...Here is my code:

use File::Find::Rule; use Win32; @cuvintecareconteaza=('BA','test','folk'); my ($sec,$min,$hour,$day,$month,$year) = localtime(time); my $ymd = sprintf("%04d-%02d-%02d--%02d-%02d",$year+1900,$month+1,$day +,$hour,$min); my $outfile = "$ymd.txt"; my $path = "c:/TEST"; my $base_dir ='c:/TEST/'; my $find_rule = File::Find::Rule->new; my $find_rule1 = File::Find::Rule->new; # Do not descend past the first level $find_rule->maxdepth(1); # Only return directories $find_rule->directory; $find_rule1->file; #dimensiune fisier de baza find({follow => 0, wanted => sub { $size_total += -s $File::Find::name || 0; }}, $base_dir); $size_total = sprintf("%.02f",$size_total / 1024 / 1024); ########################### my @files = $find_rule1->in($base_dir); open(FILE, ">>$path/$outfile") || die("Couldn't open file"); printf FILE "DIMENSIUNE '$base_dir' = + $size_total MB\n"; printf FILE "\n"; printf FILE "Fisiere care indeplinesc normele cautate +:\n"; printf FILE "\n"; printf FILE "\n"; foreach my $fisier (@files) { if ( ($fisier ne ".") and ($fisier ne "..") ) { use File::Find; my $size=0; find( sub {-f and ($size += -s)},$fisier); $size = sprintf("%.02f",$size / 1024 / 1024); use File::Basename; my $filename = basename( $fisier ); open(FILE_IN, $fisier) || die("Couldn't open file"); @read=<FILE_IN>; foreach $cuvintecareconteaza(@cuvintecareconteaza) { chomp @read; Win32::MsgBox("'$cuvintecareconteaza' ---- '$fisie +r'" ,48,'Alerta'); if(grep(/\b$cuvintecareconteaza\b/i,@read)) { printf FILE "'$fisier' ---- '$cuvintec +areconteaza'\n"; } else { printf FILE "Sorry, this word was not found in ' +$fisier'\n"; } } close(FILE_IN); } } close(FILE);

Please help me....


In reply to Searching through a word file using an array element by coldwish

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.