• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Shell-Perl-AppleScript scripting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: Re: QuarkXPress - Text Style Ranges: is this a bug?
  • Next by Date: Re: QuarkXPress - Text Style Ranges: is this a bug?
  • Previous by thread: Re: New AppleScript book (AppleScript: the Definitive Guide!)
  • Next by thread: Re: Shell-Perl-AppleScript scripting
  • Index(es):
    • Date
    • Thread