Hi Monks,

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

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.