From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25253 invoked by alias); 18 Mar 2017 17:06:31 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 40861 Received: (qmail 20622 invoked from network); 18 Mar 2017 17:06:31 -0000 X-Qmail-Scanner-Diagnostics: from mail-ua0-f177.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.217.177):SA:0(-0.0/5.0):. Processed in 1.171814 secs); 18 Mar 2017 17:06:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.217.177 as permitted sender) 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=56rNTgkfgkrDAFZMjOyfKRqqsOm3OuOReOQ3EFDQzlI=; b=ARwBShF6nix7sUk6PENYX+Yr7MsfZ+wLPbgTj6kQhqHKCbBAovj5PtMxES03eYZhLT M+8rgI5WgNh4l6xvSYskBCXfvctHog2Szk7FMPXFzWh8YQryP328fy66C5wtV49BY/Eb egf4sKPN0hjQ162W4uWMP2hNqL0ChGvQ1mtXsnSc0kCH5OVyqefIORx9zHKswXbRE1t9 gSC3dnRct8zdOO5fVB3vU1qaFkvoQwnviKUxBp+o1fmKZx2HcnlNzfkH5d7rpJcxdOAA LCrPB9a222i8iZZ9NNY8z0yhTDJfwsy4uXKi/gQkQrmfFceK7IgIuYBfuN5eROH2VWIY s91A== X-Gm-Message-State: AFeK/H2gNtJp265xVRX9P5buRqTBxh2kNXfmWpMPBYGotN0FvoYHjoF90nBkFfes6aMhwg== X-Received: by 10.176.74.150 with SMTP id s22mr7412360uae.85.1489856782124; Sat, 18 Mar 2017 10:06:22 -0700 (PDT) From: Bart Schaefer Message-Id: <170318100710.ZM24526@torch.brasslantern.com> Date: Sat, 18 Mar 2017 10:07:10 -0700 In-Reply-To: <1489849991.578651.915517240.3CDC6181@webmail.messagingengine.com> Comments: In reply to Sebastian Gniazdowski "Append to array via (P) flag" (Mar 18, 8:13am) References: <1489849991.578651.915517240.3CDC6181@webmail.messagingengine.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: Append to array via (P) flag MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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?