Nice.

Once again, I suggest not hardwiring theColNum because it could change... but you could always make a separate handler that figured out the column number from a header row, lookup table or other criteria, then call this handler.


On Jul 17, 2007, at 1:26 PM, Gregory Lypny wrote:

Hello Josh,

Here's the final version of the function. Thanks to everyone for their suggestions. I know there are other features and better error-checking that can be added. Maybe later. It can extract roughly 75 records from 700 in 1 tick on an Intel-based iMac.

Regards,

        Gregory

function filteredByColumn theData,theColNum,theSearchString,isWithout
  -- This function filters tab-delimited data by column
-- By default the filter extracts lines containing the search string. Make isWithout = "without" to extract lines without it. -- Possible mods: options to make "begins with" or "contains" searches
  if theColNum is an integer
  then
    set the itemDelimiter to tab
    if isWithout is empty
    then
sort lines of theData by (item theColNum of each is not theSearchString) -- Brings lines with theSearchString to the top
      repeat for each line thisLine in theData
        if item theColNum of thisLine is theSearchString
        then
          put thisLine & return after filteredData
        else
          exit repeat
        end if
      end repeat
    else
sort lines of theData by (item theColNum of each is theSearchString) -- Brings lines without theSearchString to the top
      repeat for each line thisLine in theData
        if item theColNum of thisLine is not theSearchString
        then
          put thisLine & return after filteredData
        else
          exit repeat
        end if
      end repeat
    end if
    delete the last character of filteredData
    return filteredData
  else
    return "The column number must be an integer."
  end if
end filteredByColumn






On Mon, Jul 16, 2007, at 7:49 PM, Josh Mellicker responded:

On Jul 16, 2007, at 2:04 PM, Gregory Lypny wrote:

I tested the function below, which is much like Josh's, and it
filters more than 300 lines in 1 tick; the same code as a message
handler rather than a function takes 5 ticks; and the filter
command on the same data takes 39 ticks.


Wow, I thought that handler was fast, but never tested/compared it.

I wonder if sorting the lines by columnNum, then exiting on the first
non-matching line would be faster or slower?


_______________________________________________
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

_______________________________________________
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to