zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: zsh-users@zsh.org
Subject: Re: proxy name for array
Date: Wed, 10 Jan 2024 13:11:34 -0800	[thread overview]
Message-ID: <CAH+w=7Ymp7US1A=BXWgA_+J5UVRw0Zz0k8Fh50SEAZ5QGYPm0Q@mail.gmail.com> (raw)
In-Reply-To: <4e5aa5cf-dfad-4e0c-ac38-8631d1c4ccbc@eastlink.ca>

On Wed, Jan 10, 2024 at 12:26 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
>      temp=( ${(P)${(P)1}[pages]} )    # Temporary array will be used to
> hold content of 'Pages' (or whatever else).
>      temp[2]=50                       # Set some test values.

Yes, you could avoid temp with

  set -A "${${(P)1}[pages]}[2]" 50
  set -A "${${(P)1}[pages]}[3]" 100
  set -A "${${(P)1}[pages]}[4]" 150

but that's not as clear or easily maintainable.  You could also do

  temp=${${(P)1}[pages]}  # Note one less (P) and not an array
  set -A "${temp}[2]" 50
  set -A "${temp}[3]" 100
  set -A "${temp}[4]" 150

or even

  set -A "${temp}[2,4]" 50 100 150

All three of the above would avoid the need to write an entire array
back as the last step, but unless you're dealing with huge arrays the
best form is the one you understand.


  reply	other threads:[~2024-01-10 21:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-09 18:59 Ray Andrews
2024-01-10  0:21 ` Bart Schaefer
2024-01-10  0:54   ` Ray Andrews
2024-01-10  2:29     ` Bart Schaefer
2024-01-10  2:58       ` Ray Andrews
2024-01-10  3:05         ` Bart Schaefer
2024-01-10 13:44           ` Ray Andrews
2024-01-10 20:26           ` Ray Andrews
2024-01-10 21:11             ` Bart Schaefer [this message]
2024-01-10 21:22               ` Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7Ymp7US1A=BXWgA_+J5UVRw0Zz0k8Fh50SEAZ5QGYPm0Q@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).