Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Append to array via (P) flag
- X-seq: zsh-workers 40861
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: Append to array via (P) flag
- Date: Sat, 18 Mar 2017 10:07:10 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=56rNTgkfgkrDAFZMjOyfKRqqsOm3OuOReOQ3EFDQzlI=; b=lRiK/vWbEQYBfR7yR9m/Hx9X8HFeJ9A8dfw3ob8y0nitJoWy3jWOdjHrfPLgXBKloO DffB9IYVUp1joDVRd9MZmRAb1JEMHS+iNfY+MpsKP9siWsWq/imsD3ih1tq/R75lidI/ OLCqPj8wthyRfGsIBJUWi+Zsrfi0NMWUTl1ZjnqMsGTShM3DCN3w9n2kNfw2+hotH560 iioyP4gqoHjzOsF2/f1leioKnyD4GyKrsZPB92WLpe0xHq1o+89bSx/XMMZRShqPEHbA F4skgy+/dDBIngGg0ExnHhJouLqQe6xFJDpmnhurj36vbJtEK4gBaITqqL/H047i5HbY w/6A==
- In-reply-to: <1489849991.578651.915517240.3CDC6181@webmail.messagingengine.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <1489849991.578651.915517240.3CDC6181@webmail.messagingengine.com>
On Mar 18, 8:13am, Sebastian Gniazdowski wrote:
}
} Problem is in API function that does:
}
} __output=( "${(P@)__var_name}" "New data" )
} : ${(PA)__var_name::=${__output[@]}}
You can already do this, you just need to know the length of the
array so that you can index past the end of it:
__output=("New Data" "Like this")
__append="${__var_name}[${(P)#__var_name}+1]"
: ${(PA)__append::=${(@)__output}}
With extendedglob set I'm pretty sure this will work in all cases:
__append="${__var_name}[(r)(^*)]"
: ${(PA)__append::=${(@)__output}}
The pattern (^*) will never match, ${(P)__append} will always be off
the end of the array, and there you go. But that might actually be
less efficient than the extra ${(P)#__var_name}.
You can also insert stuff into the middle of an array by using a
reverse-ordered subscript, e.g. to shove the new values in between the
fifth and sixth elements:
__insert="${__var_name}[6,5]"
: ${(PA)__insert::=${(@)__output}}
Out of idle curiousity, why would you write a new text editor when
you can already use "vared" on a memory-mapped file?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author