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

Re: triviality regarding $# counts





On 2024-04-14 07:06, Mark J. Reed wrote:

What? No.  Why do you keep bringing (f) into this? That flag has nothing to do with copying; in fact it intentionally changes things: anywhere there used to be a single string containing a newline,you get two strings instead.
% hhh=( "${(@f)iii}" )
% typeset -p hhh; typeset -p iii
typeset -a hhh=( 'abc\ndef\nghi' )
typeset iii='abc\ndef\nghi'

... newlines still there.  One element. 


Besides it worked as I showed.

But if you drop the f, you do get your Xerox copy:

% fff=( "${(@)ddd}" )
... so far so good with tests.  The (f) seems not to have removed anything -- I was sure it did, yesterday :( -- but that was then.  But yours seems to work and it's simpler, more intuitive.  The (f) does not seem to be missed, either.  And to think that just yesterday I thought I had this all sorted.

Would it be nicer if you could just do fff=$ddd and not have to include the parens and quotes and @? Sure. You could even make a case that it should work that way, since we're in Zshland where $ddd expands to the whole array instead of a single element. But that's not the way assignment works. Though, as I said, if the array has no empty elements, you can get away with just fff=($ddd).
'IF' ... what I'm wanting is some universal copy that has no gotchas.

BTW, just philosophically speaking, the parens are an interesting question.  Whereas I'd say that a copy is a copy is a copy:

aaa=$bbb

... so whatever bbb may happen to be, aaa will become the same.  But if aaa is a scalar, should it be promoted 'silently' ?  Seems to me the parens are explicit that aaa will become an array so I like them.  One can never be too clear as to what's happening.

cut




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