Re: scripting MacPerl question
Re: scripting MacPerl question
- Subject: Re: scripting MacPerl question
- From: Ricardo Montiel <email@hidden>
- Date: Thu, 05 Jul 2001 17:43:47 -0300
on 04/07/2001 22:32, Ingo Bitsch at email@hidden wrote:
>
Thanks, Ricardo! That was very helpful!
You're welcome, Ingo; my pleasure.
>
I was not yet able to get your example to run with my script,
>
though. I suspect the problem to be a couple of Applescript
>
special characters like "/" and """ in the Perl Script. I tried
>
to escape those characters with "\", but then I got an error in
>
MacPerl...
Special characters that wasn't correctly escaped would be the most probable
cause of errors. As long as I know, the slash ("/") doesn't need to be
escaped, but the backslash ("\") and the quote (""") does. See the line with
the perl print command for details:
--- Begin Script --------
tell application "MacPerl.PPC"
set xProcess to "
#!/usr/bin/perl -w
use strict;
my %Hash = qw (computer Macintosh model PPC);
foreach (keys(%Hash)){
print \"$_\\n\";
}"
set xProcessedText to ,
Do Script {xProcess} mode Batch
end tell
display dialog xProcessedText with icon -16396
--- End Script ----------
But I agree that escaping characters isn't a joyful way to go. And I have in
mind those complex matching patterns... So the former stands for a good
reason to only use AppleScript as a front end application that calls an
external perl script (as you wrote below). For peace of mind, try to not mix
AppleScript and Perl unless you must do it.
>
So I would rather leave the Perl Script in an external
>
MacPerl file and tell Macperl to run this script. Do you know the
>
syntax for this? I tried your script with the modified line
>
>
Do Script {"test.pl", xText} mode Batch
>
>
but it doesn't seem be that simple...
Indeed, it's simple, it's the way AppleScript works. It is required the path
to the script file, not only its name:
First: save the Perl script as you'd normally do with a common perl script
(I used the same code as above - remember to strip out the escaped
characters):
--- Begin Perl Script --------
#!/usr/bin/perl -w
use strict;
my %Hash = qw (computer Macintosh model PPC);
foreach (keys(%Hash)) {
print "$_\n";
}
--- End Perl Script ----------
Second: Run the next AppleScript (it displays the same result as the first
script of this message).
--- Begin Script --------
-- set up the path to the Perl script
set xFileRef to file "Byrm2a:Desktop Folder:Prueba_Ingo.pl"
tell application "MacPerl.PPC"
set xProcessedText to ,
Do Script {xFileRef} mode Batch
end tell
display dialog xProcessedText with icon -16396
--- End Script ----------
>
And BTW: What is the syntax for your preferred way (writing to
>
disk?).
Really nothing special - it's a pure and simple Perl print command: the
output will be exclusively controlled by the Perl code.
I hope this helps,
Saludos (Regards),
-- Ricardo Montiel
Buenos Aires, Argentina
PS: Please cc me, on digest.