Yesterday I saw a question from gzayzay that I took interest in. I had been fumbling around to figure out if it was possible to search the data for files that contained two or more of the words entered.
print "\nEnter your words (separated by spaces): >> "; chomp(my $line = <STDIN>); my @words = split /\s+/, $line; foreach $word(@words) { if() { #Set a condition to match more than one word, i.e to match combinat +ion of multiple words } else { open(FH, $kwords)&& open(MN, ">>$sResult") || die ("Cannot open [$k +words,$sResult], $!\n"); print RESULT "==============================\n"; print RESULT "\t ", uc($word),"\n"; print RESULT "==============================\n"; { local $/=undef; print RESULT grep { $_ =~ /$word/i } <SEARCH> =~ m!(<MS_\d+>.*?</ +MS_\d+>)!gs; } print MN "\n"; close MN; close FH; } __DATA__ <MS_1> <loc>c:\data\cat.xml</loc> <words>dog, cat, fish, bird</words> </MS_1> <MS_2> <loc>c:\data\cow.xml</loc> <words>dog, cat, fish, bird, cow, goat</words> </MS_2> <MS_3> <loc>c:\data\snake.xml</loc> <words>dog, cat, fish, bird, snake, orange</words> </MS_3>
As the code is above, suppose there is another file having combination of the user input. if the user enters cat, eagle and a file MS_4 has,
<MS_4> <loc>c:\data\fat.xml</loc> <words>snail, cat, eagle, fly, chicken, elephant</words> </MS_4>
Can any Monk help with a code that will promt the user that a file contain both or all of the input and continue to find other files that have only one of the inputs? I thought this was a good try but it is giving me a great day.
Happy coding to all Monks attempting....
2006-04-07 Retitled by g0n, as per Monastery guidelines
Original title: 'Addition to gzayzay question'
In reply to Finding some/all of given words in a file by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |