fork download
  1. #!/usr/bin/perl
  2.  
  3. use warnings;
  4. use strict;
  5.  
  6. $\ = $/;
  7.  
  8. $_ = <>, chomp;
  9. my @sen = map { s/^\s+|\s+$//gr } map { split m/[.]\K\s+(?=[A-Z0-9])/ } split m/[!?]\K/;
  10. my %H;
  11. for my $sen (@sen){
  12. while( $sen =~ m/\w+/g ){
  13. $H{ $sen }{ lc $& } = 1;
  14. }
  15. }
  16.  
  17. <>;
  18.  
  19. while(<>){
  20. m/\w/ or next;
  21. my( @words ) = map lc, m/\w+/g;
  22. my @found;
  23. for my $sen (keys %H){
  24. my $f = 0;
  25. for my $w (@words){
  26. $H{ $sen }{ $w } or $f = 1;
  27. }
  28. $f or push @found, $sen;
  29. }
  30. print "Search results for \"$_\":";
  31. print "- \"$_\"" for @found;
  32. }
Success #stdin #stdout 0s 6188KB
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":