Re: Coerce String to Handler?
Re: Coerce String to Handler?
- Subject: Re: Coerce String to Handler?
- From: Timothy Bates <email@hidden>
- Date: Tue, 17 Apr 2001 14:35:44 +1000
On 17/04/2001 7:30 AM, "Chris Nebel" <email@hidden> wrote:
>
You can bind any known-in-advance handler to a variable, but you
>
can't do it based on an arbitrary string.
This is handled very smoothly in PHP (he said, hoping not to invoke the
NIMBY syndrome).
I used it the other day in a cgi which receives a variable number of inputs,
each referring to a new student. I needed to be able to say. I could grab
the studentID as "ID#" and then I wanted to say:
set <gradeTotalID#> to <grade1ID#> + <grade2ID#>
before uploading the grade into MySQL.
In php, it was easy to turning these arbitrary strings into variable names
(the variables already existed of course, passed in by php, I just need to
be able to refer to them on the fly).
I just said:
$thisGrade1 = "grade1" . ID# ;
echo($$thisGrade1);
--> grade 1 for student with ID #
or in applescript syntax
set grade1 to "grade1" & ID#
get $grade1
(where adding the "$" in front of the variable means "I want you to use the
contents of this variable as a variable"
works a charm.
I am just about to submit this functionality as a request for an applescript
enhancement and hope that others who are also wanting to turn AppleScript
into a great embedded language for driving the internet will follow suit.
tim