Subject: Re: [ast-users] Fast way to read a file into an array variable?
--------
> I'd like to a read potentially large files (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. (As an example, The zsh configure
> script is over 20,000 lines long).
>
> I know about redirecting input in a loop and/or alternatively using
> "read" in a loop. But for a large file this tends to be slow. As a
> result, both bash and zsh have a mechanism for doing this faster than
> using a read loop. For zsh the speed difference was 0.189 seconds (to
> load zsh and the module and read) versus over a minute. For bash the
> difference in speeds is, I believe, even greater.
>
> So what's the fastest way to large read a file into an array?
>
> Thanks.
>
The function below reads a file of 20,000 80 byte lines into a file into
a an index array in .07s on Linux.
==================cut here============================
function readfile # var file
{
nameref var=$1
set -f
IFS=$'\n\n'
var=( $(< $2))
}
==================cut here============================
David Korn
[EMAIL PROTECTED]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users