in reply to Re: emulate "fgrep -f file" with results ordered by "file"
in thread emulate "fgrep -f file" with results ordered by "file"

thanks for the suggestion - chmop worked. There is one other problem - it is fairly slow. There are about 1M itmes to grep from @list and @large has a few more lines than that (about 1.2M )..any ideas on how to do this more efficiently?
  • Comment on Re^2: emulate "fgrep -f file" with results ordered by "file"

Replies are listed 'Best First'.
Re^3: emulate "fgrep -f file" with results ordered by "file"
by Eliya (Vicar) on Mar 15, 2011 at 02:59 UTC

    You could create an index (=hash lookup table) by the first field of 'large'.  Then loop over @list and check if the key exists in the lookup table.

    Something like

    my %index; while (<DATA>) { # your $large my ($f1) = split; $index{$f1} .= $_; } my @list = qw(foo r2c1 bar r3c1); for (@list) { print $index{$_} if exists $index{$_}; } __DATA__ r1c1 r1c2 r1c3 r2c1 r2c2 r2c3 r3c1 r3c2 r3c3
      thankyou very fast indeed!