Re: Setting AS Var to Perl Result
Re: Setting AS Var to Perl Result
- Subject: Re: Setting AS Var to Perl Result
- From: "Mark J. Reed" <email@hidden>
- Date: Mon, 29 Nov 2010 12:46:09 -0500
On Mon, Nov 29, 2010 at 11:23 AM, Marconi <email@hidden> wrote:
> I have an assortment of data files consisting of multiple lines that are:
>
> DatumName : DatumValue
> I'd like to call the Perl script with a command line consisting of:
>
> /path/to/the/contained/perl/script /path/to/the/dropped/data/file.txt
> name_of_datum_to_extract
That can be done as a one-line Perl command, with no separate
standalone script required. If the format is just
DatumName:DatumValue
with no spaces around the colon, then something like this should do the trick:
set datumValue to (do shell script "perl -F: -lane 'BEGIN { $datum =
pop @ARGV } print $F[1] if $F[0] eq $datum' " & (quoted form of posix
path of dataFile) & " " & (quoted form of datumToExtract))
A more idiomatic argument order would put the datum to extract first,
and then the filename (which could then actually be any number of
filenames which would all be searched for the target datum):
set datumValue to (do shell script "perl -F: -lane 'BEGIN { $datum =
shift @ARGV } print $F[1] if $F[0] eq $datum' " & (quoted form of
datumToExtract) & " " & (quoted form of posix path of dataFile))
If there is actual whitespace around the colon that you don't want to
include in the name of the datum or its value, then you need to change
the -F option so it gets included in the delimiter:
set datumValue to (do shell script "perl -F'\\s+:\\s+' -lane 'BEGIN {
$datum = shift @ARGV } print $F[1] if $F[0] eq $datum' " & (quoted
form of datumToExtract) & " " & (quoted form of posix path of
dataFile))
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden