Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shell-Perl-AppleScript scripting



I briefly tried the quoting construct you describe and couldn't get anywhere. I'll try it some more. Thanks.

John Fowler

On Dec 28, 2003, at 4:47 PM, Randal L. Schwartz wrote:

John> on perlreplace(inputstring, targetstring, replacementstring)
John> set shellscript to "/usr/bin/perl -e '$rpl=q|" & replacementstring &
John> "|;$trgt=q|" & targetstring & "|;$thisvar=q|" & inputstring &
John> "|;$thisvar=~s/$trgt/$rpl/sg;print $thisvar;'"
John> log shellscript
John> set theResult to (do shell script shellscript)
John> return theResult
John> end perlreplace

John> The remaining problem appears to be that the quote character (| in this
John> case, but others are legal in perl) can't be part of the target or
John> replacement strings. As far as I can tell, no combination of
John> quotemeta() or "quoted version of" completely solves this problem. In
John> my trials, one version, with quotemeta() applied to the replacement
John> string, yielded output complete with the backslashes rather than
John> de-backslashed. Any suggestions would be welcomed.

The general strategy for a good delimiter is like this:

BEGIN {
chomp($search = <<'UnLiKeLyStRiNg');
your search string goes here, as is
UnLiKeLyStRiNg
chomp($replace = <<'UnLiKeLyStRiNg');
your replace string goes here, as is
UnLiKeLyStRiNg
}
s/$search/$replace/g;

Although my AppleScript-fu is too weak to know how to get the right
newlines in this code. :)
_______________________________________________
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.

References: 
 >Shell-Perl-AppleScript scripting (From: John Fowler <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.