Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: proxy name for array



On Wed, Jan 10, 2024 at 12:26 PM Ray Andrews <rayandrews@xxxxxxxxxxx> 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.




Messages sorted by: Reverse Date, Date, Thread, Author