set var to foo; get var of record?
set var to foo; get var of record?
- Subject: set var to foo; get var of record?
- From: Terje Bless <email@hidden>
- Date: Thu, 17 Oct 2002 20:20:47 +0200
Revealing my ineptitude to the world... :-)
I'm a reluctant AppleScripter coming in from Perl land and trying to
replicate the behaviour shown by the following Perl snippet:
$variable = "key1";
%hash = (key1 => 'value1', key2 => 'value2');
if (exists $hash{$variable}) {
$result = $hash{$variable}; # $result is now "value1".
}
That is, create a record of key=value pairs, set a variable to one of the
key names, and then fetch the value of the key whose name is in the
variable. Naively, I attempted:
set variable to "key1"
set hash to {key1:"value1", key2:"value2"}
if (hash's variable) then
set result to hash's variable
end if
but this obviously didn't work too well. Can anyone give me an example of
how to do this, or point me at documentation explaining it? If the latter
is "The AppleScript Language Guide", please point me at the correct bit of
it; i've trawled it for the right info but come up empty.
Examples in general of working with datastructures slightly more complex
then lists would also be most welcome!
The problem I'm trying to solve is in matching an email address to a
sending account (or "Personality" in Eudora's terms), changing the sending
account depending on which email address originated the message being
replied to. I realise there are other ways to achieve this, but this method
is one I've often wanted in AppleScript (because it works so well in Perl).
I suppose it's really a lookup table, but one with a bit of indirection
thrown in and that's the bit that is tripping me up in AppleScript.
_______________________________________________
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.