[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] That Do Script thing



hello,

on 9/7/00 5:56 PM, Chris Nandor at pudge@pobox.com wrote:

> This doesn't work for me.  But it gave me an idea.  This DOES work:
> 
> set myScript to "print join '|', @ARGV"
> set myList to {"a", "b"}
> tell application "MacPerl" to Do Script [myScript] & myList mode Batch
> 
> The trick is to first coerce the script string (whether it is a filename or
> the text of the script) into a list, and then & will combine the lists into
> one list.  I knew there was a way to do it ...

Yes.  It looks like the problems may be related to how applescript
interprets what you are trying to do.  For example,

set myList to "print join '|', @ARGV" & {"a", "b"}

yields -> "print join '|', @ARGVab"

so it looks like applescript is coercing {"a", "b"} to a string before
performing the & operation.  However,

set myList to {"a", "b"} & "print join '|', @ARGV"

yields -> {"a", "b", "print join '|', @ARGV"}

so it looks like applescript is coercing "print join '|', @ARGV" to a list
before performing the & operation.  This must be tied to which comes first.
Workarounds are being explicit so that applescript doesn't have to guess
which you want, a list or a string:

set myScript to "print join '|', @ARGV" as list
set myList to {"a", "b"}
set myList to myScript & myList

-> {"print join '|', @ARGV", "a", "b"}

OR

set myScript to {"print join '|', @ARGV"}
set myList to {"a", "b"}
set myList to myScript & myList

-> {"print join '|', @ARGV", "a", "b"}

So appying these principles:

This works:

set myList to {"print join '|', @ARGV", "a", "b"}
tell application "MacPerl" to Do Script myList mode Batch

This also works:

set myScript to "print join '|', @ARGV"
set myList to {"a", "b"}
copy myScript to the beginning of myList
tell application "MacPerl" to Do Script myList mode Batch

This also works:

set myScript to "print join '|', @ARGV" as list
set myList to {"a", "b"}
tell application "MacPerl" to Do Script myScript & myList mode Batch

This also works:

set myScript to "print join '|', @ARGV"
set myList to {"a", "b"}
tell application "MacPerl" to Do Script {myScript} & myList mode Batch

This also works:

set myScript to "print join '|', @ARGV"
set myList to {"a", "b"}
tell application "MacPerl" to Do Script (myScript as list) & myList mode
Batch

I'm sure there are many more ways ...

-- 
Enrique Terrazas, MD, MS
<mailto:terrazas@labmed.ucsf.edu>
<http://labmed.ucsf.edu/~terrazas/>



# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org