Re: applescript-users digest, Vol 2 #367 - 17 msgs
Re: applescript-users digest, Vol 2 #367 - 17 msgs
- Subject: Re: applescript-users digest, Vol 2 #367 - 17 msgs
- From: email@hidden
- Date: Wed, 14 Feb 2001 19:24:00 EST
In a message dated 2/14/01 10:29:02 AM, Serge Belleudy-d'Espinose wrote:
>
At 13:13 -0700 11/02/01, Byron Peterson wrote:
>
>
>What is the fastest way to remove an item from a large list (the list I'm
>
>working with has about 3000 items in it). The item I need to remove is in
>
>the middle of the list and it isn't the same item every time.
>
>
Ok, now that everyone answered, what if someone wants to remove an item
knowing
>
only its content, not its index?
<snip first solution>
>
Then another solution based on TIDs
>
>
on remove_from_list (xItem, xList)
>
set {oldTID, AppleScript's text item delimiters} to +;
>
{AppleScript's text item delimiters, return}
>
set xList to "" & xList's items
>
set AppleScript's text item delimiters to xItem
>
set xList to xList's text items
>
set AppleScript's text item delimiters to oldTID
>
set xList to "" & xList's items
>
set AppleScript's text item delimiters to (return & return)
>
set xList to (xList's text items)
>
set AppleScript's text item delimiters to return
>
set xList to ("" & xList's items)'s text items
>
set AppleScript's text item delimiters to oldTID
>
return xList
>
end remove_from_list
>
>
(watch for +; as continuation char)
Simplified version for you
on remove_from_list(xItem, xList)
if item 1 of xList is equal to xItem then return rest of xList
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text
item delimiters, return}
set xList to xList as string
set AppleScript's text item delimiters to (return & xItem) -- the
difference
set xList to (text items of xList)
set AppleScript's text item delimiters to ""
set xList to xList as string
set AppleScript's text item delimiters to return
set xList to text items of xList
set AppleScript's text item delimiters to oldTID
return xList
end remove_from_list
>
To my surprise, despite all the string manipulations this one proved
constantly
>
2x faster.
>
I've been scripting for one year now. My main concern is not only 'how to do
it'
>
but also 'how to do it FAST', and I'm increasingly using the power of TIDs.
I've been scripting for 5 years and have been using text files and the TIDs
to handle flat file data. I have looked at numerous other options and find
this to be hands down the fastest way to do it. It does limit flexibility a
bit, but for flat file data management it really is a winner combination of
tools. I am using this technique to build what will eventually be a one
million field read only data source.
Jeff Baumann
email@hidden
www.linkedresources.com
I need a new witty signature....