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

Re: BUG: zsh-3.1.5-pws-14: parameter expansion not working properly



On Apr 16, 11:48am, Andrej Borsenkow wrote:
} Subject: RE: BUG: zsh-3.1.5-pws-14: parameter expansion not working proper
}
} It is *impossible* to split array elements. It is no joke. Arrays are joined
} together before splitting - so, the result I get is much much different.
} 
} Subsequent splitting on IFS does not help, as it can change "too much"
} 
} May be, nobody really needs it (I missed it time to time). And may be, there
} is always workaround. But it is really really weird ...

The obvious workaround is to explicitly join and then split:

zsh% foo=(a:b x:y)
zsh% print -l ${(j/:/s/:/)foo}
a
b
x
y

One might however argue that this looks odd:

zsh% print -l ${(s/:/j/:/)foo}
a
b
x
y

The flags are always applied in an internally-defined order, not in the
order they appear in the flag list.  But flag list ordering does matter
if you happen to repeat a flag:

zsh% print -l ${(s/:/s/ /)foo}
a:b
x:y

All that aside, a desirable (?) effect of the current interpretation is
that join reverses split (except for the initial array-to-scalar change):

zsh% print -l ${(j/:/)${(s/:/)foo}}
a:b x:y

With your interpretation, this would yield a:b:x:y.  Of course, since
split can't logically reverse join, maybe it's not necessary that join
be capable of reversing split.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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