fork download
  1. #!/usr/bin/perl
  2.  
  3. use warnings;
  4. use strict;
  5.  
  6. $\ = $/;
  7.  
  8. $_ = <>, chomp;
  9. my @sentences = map { s/^\s+|\s+$//gr } map { split m/[.]\K\s+(?=[A-Z0-9])/ } split m/[!?]\K/;
  10.  
  11. <>;
  12.  
  13. while(<>){
  14. m/\w/ or next;
  15. my( @words ) = m/\w+/g;
  16. my @found = @sentences;
  17. for my $word (@words){
  18. @found = grep m/\b$word\b/i, @found;
  19. }
  20. print "Search results for \"$_\":";
  21. print "- \"$_\"" for @found;
  22. }
Success #stdin #stdout 0s 6180KB
stdin
  abc . If op ? . . Nud . pl ! um isp .  
8
abc
if
nud
isp
op   nud
op if
if o
stdout
Search results for "abc":
- "abc ."
Search results for "if":
- "If op ?"
Search results for "nud":
- "Nud . pl !"
Search results for "isp":
- "um isp ."
Search results for "op   nud":
Search results for "op if":
- "If op ?"
Search results for "if o":