| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
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. :)
| References: | |
| >Shell-Perl-AppleScript scripting (From: John Fowler <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
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.