in reply to Re^7: search array for closest lower and higher number from another array
in thread search array for closest lower and higher number from another array

t is 15 seconds for my grep method

...but your grep method is only doing half of the work right?

It gets you a big chunk of lines (context) either side of the line containing the search term, but it doesn't restrict them to just the enclosing section you are interested in. So, basically it is only doing half the job. Little wonder that it is quicker?

However, this might be what you're looking for. It gets the time down to 12 seconds on my machine:

#! perl -sw use strict; my $term = shift; $/ = 'Header'; while( <> ) { chomp; print 'Header', $_ if 1+index $_, $term; } __END__ [11:28:45.37] c:\test>junk34 lima 886391.dat >junk.dat [11:28:57.83] c:\test>

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^8: search array for closest lower and higher number from another array
  • Download Code

Replies are listed 'Best First'.
Re^9: search array for closest lower and higher number from another array
by bigbot (Beadle) on Feb 08, 2011 at 01:27 UTC
    Excellent idea! I will try this too.