Lagerman, Thomas writes: > Set -A myarray $(< file) This (with a lowercase "set") seems to put each *word* in myarray, and what I want is access by line.
It is interesting, although I am at a loss to explain how it works. -A is for associative array, right? Also given that it works on words, it doesn't match what wc seems to report: $ set -A myarray $(< ./ksh-93t-20080919/src/cmd/ksh93/RELEASE93) $ echo [EMAIL PROTECTED] 3707 $ wc ./ksh-93t-20080919/src/cmd/ksh93/RELEASE93 455 3705 22303 ./ksh-93t-20080919/src/cmd/ksh93/RELEASE93 Also there is the interesting issue of what happens if the file doesn't have a trailing newline or not. It would be nice to detect that, but make sure the text is part of the array. But thanks for the info. It is interesting to learn of these things that seem to be lurking in shell languages. > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of R. Bernstein > Sent: Tuesday, September 23, 2008 3:22 PM > To: [email protected] > Subject: [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. > _______________________________________________ > ast-users mailing list > [email protected] > https://mailman.research.att.com/mailman/listinfo/ast-users > > THE INFORMATION CONTAINED IN THIS MESSAGE AND ANY ATTACHMENT MAY BE > PRIVILEGED, CONFIDENTIAL, PROPRIETARY OR OTHERWISE PROTECTED FROM > DISCLOSURE. If the reader of this message is not the intended recipient, you > are hereby notified that any dissemination, distribution, copying or use of > this message and any attachment is strictly prohibited. If you have received > this message in error, please notify us immediately by replying to the > message and permanently delete it from your computer and destroy any > printout thereof. > _______________________________________________ ast-users mailing list [email protected] https://mailman.research.att.com/mailman/listinfo/ast-users
