in reply to GREP/Regex - Locating Words in Sentences
John#!/usr/bin/perl -w use strict; my @words = qw(foo bar); my @lines = ("foo before bar\n", "the word is foo\n", "one goes over the mountain\n", "one reaches the bar\n", "Here foo is in the middle\n", "foo on you\n", "this foobar will be regected\n"); my $istrue = 0; my $line; my $word; foreach $line (@lines) { $istrue = 0; foreach $word (@words) { if ($line =~ /\b$word\b/) { $istrue = 1; } } if ($istrue) { print $line; } }
|
---|