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

Yes I apologize it is 15 seconds for my grep method vs 50 seconds for doing it all in Perl as you've shown. I must have done something weird before to increase the time by so much.
  • Comment on Re^7: search array for closest lower and higher number from another array

Replies are listed 'Best First'.
Re^8: search array for closest lower and higher number from another array
by BrowserUk (Patriarch) on Feb 07, 2011 at 11:40 UTC
    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.
      Excellent idea! I will try this too.