Shell-Perl-AppleScript scripting
Shell-Perl-AppleScript scripting
- Subject: Shell-Perl-AppleScript scripting
- From: John Fowler <email@hidden>
- Date: Sun, 28 Dec 2003 15:29:23 -0600
According to Chris Nebel:
>
Getting the quoting of the substitution
>
command right for all possible input strings is left as an exercise for
>
the reader.
Boy, is it ever.
Here is a pretty good version of a perl-based find-and-replace handler.
on perlreplace(inputstring, targetstring, replacementstring)
set shellscript to "/usr/bin/perl -e '$rpl=q|" & replacementstring &
"|;$trgt=q|" & targetstring & "|;$thisvar=q|" & inputstring &
"|;$thisvar=~s/$trgt/$rpl/sg;print $thisvar;'"
log shellscript
set theResult to (do shell script shellscript)
return theResult
end perlreplace
The remaining problem appears to be that the quote character (| in this
case, but others are legal in perl) can't be part of the target or
replacement strings. As far as I can tell, no combination of
quotemeta() or "quoted version of" completely solves this problem. In
my trials, one version, with quotemeta() applied to the replacement
string, yielded output complete with the backslashes rather than
de-backslashed. Any suggestions would be welcomed.
John Fowler
_______________________________________________
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.