coldwish has asked for the wisdom of the Perl Monks concerning the following question:
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....
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Searching through a word file using an array element
by toolic (Bishop) on Nov 10, 2011 at 23:53 UTC | |
|
Re: Searching through a word file using an array element
by johnny_carlos (Scribe) on Nov 11, 2011 at 00:35 UTC | |
|
Re: Searching through a word file using an array element
by ansh batra (Friar) on Nov 11, 2011 at 06:08 UTC | |
| |
|
Re: Searching through a word file using an array element
by coldwish (Initiate) on Nov 12, 2011 at 14:10 UTC | |
by afoken (Chancellor) on Nov 12, 2011 at 18:02 UTC |