Zsh Mailing List Archive
Messages sorted by:
reading a file into an array. mapfile? (f)?
- X-seq: zsh-users 13233
- From: "Rocky Bernstein" <rocky.bernstein@xxxxxxxxx>
- To: "zsh users mailing list" <zsh-users@xxxxxxxxxx>
- Subject: reading a file into an array. mapfile? (f)?
- Date: Wed, 17 Sep 2008 22:53:04 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type; bh=WT4cXYv6g7IyW/YdRcQBxm2C264otbDogHJJUAwHQPU=; b=CqKaOK2CzgGfLx1HIYn1o0srFCLA63mNCV2Am4ADEKVD3+EracJvjrtRW7v+9tRcgd LIrU4YGTx86y+2FgZePCGnWN6Hw7PrVwLBpqaKcR6RHQkwD+7Ts5yFDbbqu+r9G02ofA +QDezGeggNp5gRlWCtEpGJZ/DSlbiF/OEp7cA=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=T5ufsc8G1xE+CWjKvA/eOgp6bUUXo/PqsrD0pwlIg1kWFL3RG9dMJ5x7otSCUaNvbN zuv9esc3Gos7PtzYIxoPHhitSOr3nIgz1eTmzVWWs4TKl29RXeKWTZyu6rduqYpZMKjM 03QDrkbVuR3Bd0/hTOUMCppa1bvG+Jm44YwkQ=
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
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).
Messages sorted by: