zsh-users
 help / color / mirror / code / Atom feed
* proxy name for array
@ 2024-01-09 18:59 Ray Andrews
  2024-01-10  0:21 ` Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Ray Andrews @ 2024-01-09 18:59 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1516 bytes --]


    typeset -A body=()
    LIST=( one two three four five )
    body[array]=LIST
    proxy=$body[array] # But name of array could change.
    echo $proxy
    # Comical efforts included for a laugh ... but you see what I'm
    trying to do:
    # proxy[2]=TWO
    # $~proxy[2]=TWO
    # ${(P)proxy[2]}=TWO
    # ${(P)proxy}[2]=TWO
    # eval "${(P)proxy}[2]=TWO"
    # eval "$proxy[2]=TWO"
    # eval "${(P)proxy[2]}=TWO"
    # eval ${(P)proxy[2]}=TWO
    echo 'hoping for: one TWO three four five :-('
    echo $LIST # Not changed.

... I'm not sure I've ever attempted anything like the above.  I want 
'proxy' to hold an arbitrary array name and serve if place of an actual 
name.  '(P)' does this kind of work on the sending side of an 
assignment, but not on the receiving side and I'm not sure you can ever 
do an  expansion there anyway -- looks bloody awful. But my (usually) 
false friend 'eval' works does work like this:

     eval "${proxy}[2]=TWO" # ... and having finally nailed it, it's 
intuitive and obvious why this works and the monstrosities above do not :-(

     echo $LIST # Done!

...  But Bart always cautions against it, so I'm wondering if there's a 
more kosher way.  BTW I had previously been copying entire arrays, 
making changes and then copying them back, but why not just use the 
proxy name for whatever the actual name of the array might be?  This is 
'pointer think' of course. And I know we don't officially have pointers 
but this is a pretty good approximation.



[-- Attachment #2: Type: text/html, Size: 2025 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-01-10 21:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-09 18:59 proxy name for array 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
2024-01-10 21:22               ` Ray Andrews

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).