Re: Perl or Applescript
Re: Perl or Applescript
- Subject: Re: Perl or Applescript
- From: John Delacour <email@hidden>
- Date: Fri, 16 Aug 2002 00:03:48 +0100
At 12:43 pm -0600 15/8/02, Doug McNutt wrote:
At 13:06 -0400 8/15/02, Steven Kreuzer wrote:
>IMHO, when it comes to manipulating text, perl blows applescript
out of the water
There's no doubt about it.
How can a running AppleScript ask - er tell - perl (OS neXt) or
MacPerl (OS 9) to run a one liner which accesses the regular
expression processor and returns a result as a record containing $1,
$2, . . as a hash available for later use in the AppleScript?
perl as an OSAX?
I'm not sure quite what you mean, but whatever it is, there is no
problem. I've only got MacPerl to play with till Monday but the
thing would be the same in OS X. The script below turns a perl hash
into an AppleScript record, since that's something like what you're
talking about, and the only time-consuming bit will be the 'run
script' bit.
I have never bothered with any of the Apple Events stuff in MacPerl
because it is always faster to build the perl stuff as a string to
send in a do script or do shell script than to wait for MacPerl or
perl to compile the events, which always has to be done. The
difference is speed is painfully noticeable on slowish machines.
Therefore I believe it is always best, even in OS X, to use an
AppleScript 'do (shell) script' event to perform the task and not to
work the other way round calling AppleScript from perl, for no matter
how fast your processor, perl still has to waste time loading the
libraries and compiling the (Apple) script every time.
Working with strings in a << perl -e '.....' >> shell script is not
practical except for very simple things, and it is always best to get
perl to read the data from files or execute files.
tell app "MacPerl" to set recoString to Do Script "
%hash = (
one => 1,
two => 2,
three => 3
);
for $key (sort {$a<=>$b} keys %hash) {
$s .= qq~$key:$hash{$key},~ ;
} chop $s;
print q~{~ . $s . q~}~" mode Batch
run script recoString
set varReco to run script recoString
get varReco's one
--> 1
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.