Re: definition list recommendations?
Re: definition list recommendations?
- Subject: Re: definition list recommendations?
- From: Christopher Nebel <email@hidden>
- Date: Tue, 25 Jan 2005 21:03:59 -0800
On Jan 25, 2005, at 1:31 PM, Shane Stanley wrote:
On Tue, 25 Jan 2005 06:54:38 -0700, email@hidden wrote:
I am parsing a file and replacing codes with strings.
The codes and string definitions number just over 1850 items.
I'm listing the code as a property label and the replacement string as
the definition.
Is there a reason for making them properties and not just assigning
them
to variables?
Alternatively, why make them all variables when you can use a data
structure? If AppleScript had associative arrays, this would be really
easy, but even without them you can cut your script nearly in half by
replacing the monster list of properties and the monster list of
"if-then"s with a monster list and a short loop. Consider:
set replacement_table to { ¬
{ "r5", "<*p$>blah blah blah dare we ask who created this format?"
}, ¬
{ "cd", "yadda yadda yadda" } ¬
}
repeat with n from 1 to (count of thedata)
-- Instead of a list of ifs, use this:
repeat with i in every item of replacement_table
if item n of thedata = item 1 of i then
set currentline to item 2 of i
exit repeat -- assuming you replace at most one per line.
end
end
end
(On the other hand, I notice looking at your original that you're doing
pseudo-wildcards -- you check if thedata *is* "r5", but if it *begins
with* "cd". If that was intentional, then this sort of thing will be
harder. It's still do-able; you could add a third item in each table
element that tells you what operation to do.)
--Chris Nebel
AppleScript Engineering _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden