>Hi,
>
>Calling a macperl script (dog) from AS, with arguments a, b c, would read:
>        tell perl to do script {dog, a, b, c}
>
>Assuming that a, b, c are strings, they are copied to @ARGV in dog.
>
>The problem I have is passing a list of arguments, e.g.
>        set names to selection -- nb of selected objects not predictable
>        tell perl to do script {dog, names} -- names conversion fails
>
>Then I can converts names to a list of strings:
>        set snames to {}
>        repeat with nam in names
>                set snames to snames & (nam as text)
>        end repeat
>        tell perl to do script {dog, snames} -- dog is called, @ARGV is empty
>
>dog could be:
>        $\ = "\n"; # print with EOL
>        print "nb args: ", scalar @ARGV;
>        $" = "\n"; # separator
>        print "@ARGV";
>
>Could anyone suggest a way around ?
>
>Thanks

Hi,

I don't have MacPerl (the OS9-specific version of perl) installed anymore to
test it, but if you are really using OSX then the following does seem to work 
OK:

set names to {"one", "  two", " three"}
do shell script "perl dog.pl " & names

You do need to make sure that your items are separated by spaces... and if
"names" actually contains more complicated stuff that might include quote marks
or $ signs then you should probably use your repeat loop to produce a quoted
string using "quoted form of nam:

repeat with nam in names
        set snames to snames & " " & quoted form of nam
end repeat


Alternatively, I'm pretty sure that MacPerl had a "DoAppleScript" function:
could you turn things around to start off in perl? So instead of AppleScript
calling your perl script, your perl script calls AppleScript and gets the
selection from the returned value.

David

Reply via email to