[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Equivalent of Perl 'join' ?
From: |
John W. Eaton |
Subject: |
Re: Equivalent of Perl 'join' ? |
Date: |
Thu, 16 Dec 2010 16:30:35 -0500 |
On 16-Dec-2010, CdeMills wrote:
| To be compatible with Perl, i.e. no trimming of 'expr' and expr not included
| after the last element:
| join=@(expr, list) sprintf("%s%s", sprintf(sprintf ("%s%s", "%s", expr),
| list{1:end-1}), list{end});
|
| A big one-liner, but still an one-liner.
You could also write the innermost sprintf as
sprintf ("%%s%s", expr)
or just
cstrcat ("%s", expr)
or
["%s", expr]
Applying the same idea to the outermost concatenation, you could write
the whole thing as
join = @(expr, list) cstrcat (sprintf (cstrcat ("%s", expr), list{1:end-1}),
list{end})
or
join = @(expr, list) [(sprintf (["%s", expr], list{1:end-1})), list{end}]
Have we beaten this topic to death yet?
jwe