Re: Find index of list to find item in another list
Re: Find index of list to find item in another list
- Subject: Re: Find index of list to find item in another list
- From: Jim Skibbie <email@hidden>
- Date: Wed, 01 Jul 2009 13:20:03 -0500
- Thread-topic: Find index of list to find item in another list
Title: Re: Find index of list to find item in another list
I ended up converting the list to a comma separated string then using a ruby shell script to access Ruby’s .index method on the array:
--the really big lists
set X to {"123456", "123457", "123458"}
set Y to {{"A", "B", "C"}, {"D"}, {"E", "F"}}
-- the item I'm looking for
set Z to "123457"
set text item delimiters to ","
set X to X as string
set text item delimiters to ""
set Indexcmd to "ruby " & quoted form of "(path to shell script)/IndexInArray.rb" & " " & quoted form of X & " " & quoted form of Z
set IndexNumber to do shell script Indexcmd
if IndexNumber is not "" then set FoundThis to item ((IndexNumber as integer) + 1) of Y
where the shell script is a ruby script that takes in the long string, turns it into an array and then uses the .index method to compare if “Z” is in “X” and where it is index wise. I don’t know enough about command line ruby to know if it’s possible to wrap this all into a “do shell script” command that would not have to read in my external ruby shell script.
After all this, I’m not sure if this is faster or not. The incoming data comes from a web service, so it’s hard to judge if the whole script runs any faster iterating through the list or using the ruby shell.
Shell script for file: IndexInArray.rb
#!/usr/bin/ruby
incoming_string = ARGV[0]
does_array_contain_this = ARGV[1]
converted_array = incoming_string.split(",")
puts converted_array.index(does_array_contain_this)
Thanks.
Jim
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden