Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: reading a file into an array. mapfile? (f)?
- X-seq: zsh-users 13266
- From: Peter Stephenson <pws@xxxxxxx>
- To: "zsh users mailing list" <zsh-users@xxxxxxxxxx>
- Subject: Re: reading a file into an array. mapfile? (f)?
- Date: Fri, 19 Sep 2008 16:29:02 +0100
- In-reply-to: <080919081947.ZM30202@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <6cd6de210809171953pd956d75gd4b3609ac036fe0@xxxxxxxxxxxxxx> <080917214418.ZM27616@xxxxxxxxxxxxxxxxxxxxxx> <6cd6de210809181747kc0f0a5bt4489f534589725a8@xxxxxxxxxxxxxx> <20080919100725.5c471019@news01> <6cd6de210809190339g57a4e722u5ad1371e858c8501@xxxxxxxxxxxxxx> <200809191100.m8JB0sAC028936@xxxxxxxxxxxxxx> <080919081947.ZM30202@xxxxxxxxxxxxxxxxxxxxxx>
Bart Schaefer wrote:
> On Sep 19, 12:00pm, Peter Stephenson wrote:
> } Apologies, you're right; it seems you *do* need the @ flag, but my test
> } was too simple to show it.
> }
> } array=("${(f@)mapfile[foo.txt]}")
> }
> } I'm not entirely sure why that is but I must be misremembering the (f)
> } rules.
>
> This is a fairly recent change (well, about a year ago):
>
> For historical reasons, the usual behaviour that empty array
> elements are retained inside double quotes is disabled for arrays
> generated by splitting; hence the following:
>
> line="one::three"
> print -l "${(s.:.)line}"
>
> produces two lines of output for one and three and elides the
> empty field. To override this behaviour, supply the "(@)" flag as
> well, i.e. "${(@s.:.)line}".
Ah, yes, I remember the change. However, now you've reminded me, I
think what's changed is the ability to add the (@) to get the normal
splitting-in-double-quotes behaviour. The fact that splitting overrides
the effect of the quotes is longstanding (and in my view wrong, although
it's too late to change it).
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
Messages sorted by:
Reverse Date,
Date,
Thread,
Author