zsh-workers
 help / color / mirror / code / Atom feed
* Re: Keying arrays to names: is there an array of arrays?
       [not found]             ` <m3wtc5esxz.fsf@jin.myrkraverk.com>
@ 2006-05-29 19:18               ` Bart Schaefer
  0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 2006-05-29 19:18 UTC (permalink / raw)
  To: zsh-workers, Johann 'Myrkraverk' Oskarsson

[> zsh-workers]

On May 28,  9:32pm, Johann 'Myrkraverk' Oskarsson wrote:
}
} Bart Schaefer <schaefer@brasslantern.com> writes:
} 
} > That's actually incorrect.  The (z) option is already splitting the
} > value; you shouldn't need or want to split it again with (s: :).  If
} > the setting of IFS is preventing (z) from working properly, that's
} > probably a bug, but in any case the workaround is to make IFS local.
} 
} Well, all *I* know is that the s: : is needed -- at least without the
} local IFS solution.  If someone can (and is willing) to convince me
} that's a bug (I don't yet understand all the flags involved in these
} expansions) I can cook up some nice test case/bug report.

The (z) flag is supposed to split the line in the same way the shell
parser would split it.  IFS is only supposed to apply to "internal"
field splitting; in the case of zsh, that means sh_word_split, the
"read" builtin, etc. -- not the parser.

That is, given this test script:

    print -l foo bar
    print -l 'foo bar'
    x='foo bar'; print -l $x
    setopt sh_word_split; print -l $x

The result of

    source testscript
is
    foo
    bar
    foo bar
    foo bar
    foo
    bar

And the result of

    IFS="" source testscript
is
    foo
    bar
    foo bar
    foo bar
    foo bar

Note that parsing was unaffected, only expansion changed.

Assign those same strings to an array:

    script=( ${(f)"$(<testscript)"} )

The result of

    print -l ${(z)script}

should NOT depend on the value of IFS.  And in fact, it doesn't, in my
testing.

What may be a clue is that

    IFS=""; print -l "${(z)script}"

(quotes important) *IS* affected by the value of IFS, in that the array
elements are joined with nothing between them before the whole result is
split as if by the shell parser.  So I suspect that the reason you found
you needed (s: :) is because you had to reverse the effects of (j: :),
and you needed (j: :) in the first place because of the array joining
behavior when IFS is empty.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-05-29 19:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <m33bewj29n.fsf@jin.myrkraverk.com>
     [not found] ` <44771E3E.9070102@ulpmm.u-strasbg.fr>
     [not found]   ` <200605261540.k4QFeReG007573@news01.csr.com>
     [not found]     ` <m3wtc7gu80.fsf@jin.myrkraverk.com>
     [not found]       ` <060527151044.ZM25448@torch.brasslantern.com>
     [not found]         ` <m3ejyeg9nh.fsf@jin.myrkraverk.com>
     [not found]           ` <060528111724.ZM29224@torch.brasslantern.com>
     [not found]             ` <m3wtc5esxz.fsf@jin.myrkraverk.com>
2006-05-29 19:18               ` Keying arrays to names: is there an array of arrays? Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).