Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

Find Sentence

I have two files. One is a large block of text. It has paragraphs, where sentences wrap from line to line. The other file is just a bunch of sentences, one per line. I would like to open the file that has once sentence per line, and see if any of the sentences exist in the large text file. I have to imagine that this would be done in a sort of for each loop. Probably while reading the big text file into an array? I would like for it to echo the sentences that it finds in the big text file.

I have found:
for (@lines) {
  print if /keyword/;
}

Open in new window


Which seems to do what I want but I am not certain how to iterate the for the /keyword/ section, using each line of the other file.
0
stakor
Asked:
stakor
1 Solution
 
ozoCommented:
#!/usr/bin/perl
use strict;
use warnings;
open P,"<One" or die $!;
my $p=do{local $/;<P>};
close P;
open S,"<other" or die $!;
$p =~ s/\s+/ /g;
while( <S> ){
  my $r=$_;
  $r =~ s/\s+/ /g;
  print if index($p,$r)>=0;
}
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now