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

Re: more splitting



On Tue, Apr 14, 2026 at 6:54 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> On 2026-04-14 16:24, Philippe Altherr wrote:
> >
> > Below is a version where both, 'hex $var' and 'print -rN $var |
> > hex', produce the same result. It expects the stdin to contain strings
> > separated by NUL characters. That's why the print call has to use the
> > -N option to join its arguments with NUL characters instead of spaces.
> Your version seems good but I'm still trying to understand exactly
> what's going on.  Split on nuls you say. [...]  But, if it's split on
> nuls, where are they? [...] Or ... have you
> cleverly managed to add them and then remove them, leaving the data
> exactly as found?

They were removed by ${(0)...}.  I said "You can add things to the
stream that can later be interpreted as semantics, but then you also
have to provide the interpreter."  In Philippe's implementation,
"print -rN" adds NULs, and ${(0)...} is the interpreter that uses them
as semantics and therefore removes them again.




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