Re: Determining item number matching "x" in a list
Re: Determining item number matching "x" in a list
- Subject: Re: Determining item number matching "x" in a list
- From: John Delacour <email@hidden>
- Date: Wed, 12 Mar 2003 00:38:33 +0000
- Mac-eudora-version: 6.0a11
At 12:31 am +0100 12/3/03, Emmanuel wrote:
The loop method may be slow if your script has to perform that task
often. For a faster (yet, less direct) method, convert the list into
a string, use the Regular Expressions to locate the variable, and
then again to evaluate the index of the match.
Here's a way to get the indices of matching items using a loop in
perl, which will take no time. I think there's also a direct way to
get it, but my perl's rusty this month.
set vList to words of "one two three four three five three"
--> {"one", "two", "three", "four", "three", "five", "three"}
set vSearch to "three"
set my text item delimiters to ASCII character 10
set vString to vList as string
set my text item delimiters to ASCII character 10
do shell script "perl -e '
$string = qq~" & vString & "~ ; $search = qq~" & vSearch & "~;
for (split $/, $string){
$n++ ;
m~$search~i and print qq~$n$/~
}'"
paragraphs of result
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.