in reply to extracting non matched items from an array - the hard way!
# UNTESTED # after creating @words and @all for ( @all ) # iterate through @all, setting $_ to each in turn { my $four = ( split("\t", $_) )[3]; # split each line on \t, extract +4th field $seen{$four}++; # add to hash } # %seen hash has keys equal to the fourth field in # all the lines in @all @matched = grep { exists $seen{$_} } @words; @uniq = grep { not exists $seen{$_} } @words; # the preceding 2 lines could also have been: for ( @words ) { if ( exists $seen{$_} ) { push @matched, $_; } else { push @uniq, $_; } } # which has the advantage of iterating over @words only once.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: extracting non matched items from an array - the hard way!
by jonnyfolk (Vicar) on Jul 13, 2003 at 03:45 UTC |