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

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



I'd like to a read a file (a zsh script file) into an array fast. It is not uncommon for a GNU autoconf configure script to be tens of thousands of lines long.  (The zsh configure script is over 20,000 lines long).

I know about redirecting input in a loop or alternatively using "read" in a loop. For a large file this will tend to be slow. I also know about mapfile which reads the file and turns it into a single long zsh string. Question: if the underlying file changes, what does mapfile do? Update its data? Keep the original? Show something which is indeterminant?

There is also the zsh parameter expansion operator (f) "a shorthand for 'pws:\n:'". But I don't see how to use that with either  mapfile or input redirection to save this into an array variable short of putting this in a loop, in which case it  probably would then be no better (faster or more efficient) then doing it without the expansion operator.

One last possibility is to write a module to do what I want possibly building on mapfile. Basically this is what was done in bashdb's readarray (aka bash 4.0's mapfile).

Thoughts? Comments?

Thanks.



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