in reply to Looking for function similer to member() in SKILL
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Looking for function similer to member() in SKILL
by redhotpenguin (Deacon) on Jun 21, 2005 at 09:11 UTC | |
|
Re^2: Looking for function similer to member() in SKILL
by Limbic~Region (Chancellor) on Jun 21, 2005 at 14:33 UTC | |
by Anonymous Monk on Jun 27, 2005 at 07:52 UTC | |
by Limbic~Region (Chancellor) on Jun 27, 2005 at 12:41 UTC | |
by Anonymous Monk on Jun 27, 2005 at 14:27 UTC | |
by Limbic~Region (Chancellor) on Jun 27, 2005 at 14:31 UTC |