in reply to Online GREP problem
...so it would find any combination of the two words
You could also do it without grep and temp files:
#!/usr/bin/perl my @words = qw(we love); while (<DATA>) { # all search words must appear, but order is irrelevant my $found = 0; for my $search (@words) { $found = /\Q$search/i; last unless $found; } print if $found; } __DATA__ foo we love bar love we foo bar foo love bar we foo we bar love foo bar
Output:
foo we love bar love we foo bar foo love bar we
In place of the special DATA handle I'm using here for demo purposes, you'd use the file handle you've opened to your input file, i.e.
open my $fh, "<", $DataIn or die "Couldn't open '$DataIn': $!"; while (<$fh>) { ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Online GREP problem
by gfausel (Initiate) on Apr 05, 2010 at 21:13 UTC | |
by almut (Canon) on Apr 05, 2010 at 21:26 UTC |