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

Re: reading a file into an array. mapfile? (f)?



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