On Jun 28, 2007, at 6:36 PM, Louis Pouzin wrote:

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

Right, AppleScript doesn't have interpolating lists like Perl does.

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

'&' is a string concatentation operator. I think you mean "copy nam to end of snames". If instead you wrote 'set snames to ""', you'd tell perl to do script { dog, "foo bar baz" } rather than { dog, "foo", "bar", "baz" }.

dog could be:
        $\ = "\n"; # print with EOL
        print "nb args: ", scalar @ARGV;
        $" = "\n"; # separator
        print "@ARGV";

Could anyone suggest a way around ?

set names to {...}
set argv to names
copy dog to beginning of argv
tell perl to do script argv

(The double-set is there for clarity and can be elided.)

These days I don't use MacPerl anymore -- I have my own port of perl to a Unix-like environment that runs on classic Mac OS.

Josh


Reply via email to