Something like this?
Efficiency can be improved by ordering @arr by commonest words first. m// is a stringifying interpolated quote-like operator, so $" gets inserted between array elements, making a regex alternation.@arr = map {qr/\Q$_\E/} @arr; my @keepers = do { local $" = '|'; grep { m/@arr/ } <>; };
If that's too slow, you can make a hash with @arr as keys and look for existence over a split of your input lines.
That contains a number of tricks you may not know; default args for split, hash slice, two different $_'s in a statement.my (%hsh, @keepers); @hsh{@arr} = (); while (<>) { push @keepers, $_ if grep {exists $hsh{$_}} split; }
Reading the file line by line is not a big drag on speed if you get to only read the file once.
After Compline,
Zaxo
In reply to Re: Looking for function similer to member() in SKILL
by Zaxo
in thread Looking for function similer to member() in SKILL
by riz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |