Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: (s) splitting - is there any way to provide "dynamic" separator



On 10.10.2014 07:45, Bart Schaefer wrote:
> On Oct 9,  9:00pm, Vasiliy Ivanov wrote:
> }
> } Sorry if I (maybe) missed something obvious, but I failed to find a
> } way to use separator from parameter
> } (e.g. a='1:2:3'; sep=':'; print -l ${(s.$sep.)a}).
> 
> Something like this:
> 
>     print -l ${(ps.\0.)a//$sep/$'\0'}
> 
> (Assuming there are no nul-bytes in the value of $a to begin with.)
> 

Thanks, this seems more elegant than «eval» way, but I failed to understand this:

% a='11::22:33'; b=("${(@s.:.)a}"); print $#b
4 (as expected)

but (I expected same result)

% a='11::22:33'; sep=':'; b=("${(@ps.\0.)a//$sep/$'\0'}"); print $#b
1

while

% a='11::22:33'; sep=':'; b=(${(@ps.\0.)a//$sep/$'\0'}); print $#b
3

-- 
Regards,
  Vasiliy Ivanov <beelzebubbie.logs@xxxxxxxxx>



Messages sorted by: Reverse Date, Date, Thread, Author