Re: Shell-Perl-Applescript
Re: Shell-Perl-Applescript
- Subject: Re: Shell-Perl-Applescript
- From: Christopher Nebel <email@hidden>
- Date: Sun, 4 Jan 2004 16:59:21 -0800
On Jan 4, 2004, at 4:33 PM, Christopher Nebel wrote:
try
set shellscript to "/usr/bin/perl -0777e 'open (INFILE,\"" & theFile
& "\")||die (\"here\");$thisvar=<INFILE>;$thisvar=~s/" & targetstring
&
"/" & replacementstring & "/sg;print $thisvar;'"
This works, but I'm not fond of doing my own I/O in Perl. (I know JD
is, though his reasons escape me. Maybe something to do with
portability, or having learned Perl on a non-Unix system.) The
following would be equivalent:
set shellscript to "/usr/bin/perl -pe 's/" & targetstring & "/" &
replacementstring & "/g'" & theFile
Well, mostly equivalent -- this one won't match multi-line target
strings, since it only processes one line at a time. (To do that,
you're more or less obliged to read the whole file at once.)
It occurred to me that one can have one's cake (multi-line targets) and
eat it (short) too:
set shellscript to "/usr/bin/perl -0pe 's/" & targetstring & "/" &
replacementstring & "/sg'" & theFile
I think the "s" modifier is really only necessary if you want "." to be
able to match a line break.
--Chris Nebel
AppleScript Engineering
_______________________________________________
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.