#!/usr/bin/perl
use warnings;
use strict;
$\ = $/;
my %words = map { lc $_, 1 } m/[a-z]+/gi;
my @sentences = map { s/^\
s+|\
s+$//gr
}
my %Hash;
for my $word (@words){
my $i = 0;
for my $sentence (@sentences){
$sentence =~ m/\b$word\b/i and push @{ $Hash{ $word } }, $i; $i ++;
}
}
<>;
while(<>){
m/\w/ or next;
print "Search results for \"$_\":"; my %w = map { lc $_, 1 } m/\w+/g; my %idx;
map { $idx{ $_ } ++ } map { @{ $Hash{ $_ } } } @w;
my @idx = grep { @w == $idx{ $_ } } keys %idx; print "- \"$_\"" for map $sentences[$_], @idx; }
IyEvdXNyL2Jpbi9wZXJsCgp1c2Ugd2FybmluZ3M7CnVzZSBzdHJpY3Q7CgokXCA9ICQvOwoKJF8gPSA8PiwgY2hvbXA7Cm15ICV3b3JkcyA9IG1hcCB7IGxjICRfLCAxIH0gbS9bYS16XSsvZ2k7Cm15IEB3b3JkcyA9IGtleXMgJXdvcmRzOwoKbXkgQHNlbnRlbmNlcyA9IG1hcCB7IHMvXlxzK3xccyskLy9nciB9CgkJCQltYXAgeyBzcGxpdCBtL1suXVxLXHMrKD89W0EtWjAtOV0pLyB9IAoJCQkJc3BsaXQgbS9bIT9dXEsvOwoKbXkgJUhhc2g7CmZvciBteSAkd29yZCAoQHdvcmRzKXsKCW15ICRpID0gMDsKCWZvciBteSAkc2VudGVuY2UgKEBzZW50ZW5jZXMpewoJCSRzZW50ZW5jZSA9fiBtL1xiJHdvcmRcYi9pIGFuZCBwdXNoIEB7ICRIYXNoeyAkd29yZCB9IH0sICRpOwoJCSRpICsrOwoJfQp9Cgo8PjsKCndoaWxlKDw+KXsKCWNob21wOwoJbS9cdy8gb3IgbmV4dDsKCXByaW50ICJTZWFyY2ggcmVzdWx0cyBmb3IgXCIkX1wiOiI7CglteSAldyA9IG1hcCB7IGxjICRfLCAxIH0gbS9cdysvZzsKCW15IEB3ID0ga2V5cyAldzsKCW5leHQgaWYgZ3JlcCB7ICFleGlzdH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