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

Re: What's the reasoning behind z & s returning nular for empty input?



On Sat, 9 Nov 2019 at 08:50, Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
> On Sat, Nov 9, 2019 at 8:27 AM Sebastian Gniazdowski
> <sgniazdowski@xxxxxxxxx> wrote:
> >
> > Hi
> > arr=( "${(s:,:):-}" )
> > print -r ${#arr} ${(q)arr}
> > Output: 1 ''
>
> This makes sense. Consider how many elements we should get when
> splitting a string on commas:
>
>     split ",,," => 4 elements
>     split ",," => 3 elements
>     split "," => 2 elements
>     split "" => ???
>
> The last split could give either 1 element or 0. The former is
> consistent with the rest, the latter is not.

Thanks for the analysis. The additional problem is that quoted but
@-lacking s-flag should still elide the empty elements, as the manual
states. So this is an intentional exception and I wonder why it has
been added?

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org



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