zsh-users
 help / color / mirror / code / Atom feed
* Array indirection
@ 2006-10-03 15:54 Wojciech Pietron
  2006-10-03 17:25 ` Jean-Rene David
  0 siblings, 1 reply; 2+ messages in thread
From: Wojciech Pietron @ 2006-10-03 15:54 UTC (permalink / raw)
  To: zsh-users

ZSH_VERSION=4.0.2

Hello,

I need to analyze a couple of arrays and decided to take advantage of
indirection:

==================================================
#!/bin/zsh

names=(peter ann)
digits=(one two three four)
analyze=(names digits)

for t in $analyze; do
    for ((i=1; i<=${(P)#t}; i++)); do
        #No problems with displaying the indirect tables
        echo ${(P)t}
    done
done
==================================================

I have no problems with displaying the contents of the indirect table
inside of the inner loop but how can I do the following operations there:
- displaying i-th element of the array;
- setting i-th element of the array.

I would appreciate any help.
Best regards,
Wojciech Pietron


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

* Re: Array indirection
  2006-10-03 15:54 Array indirection Wojciech Pietron
@ 2006-10-03 17:25 ` Jean-Rene David
  0 siblings, 0 replies; 2+ messages in thread
From: Jean-Rene David @ 2006-10-03 17:25 UTC (permalink / raw)
  To: zsh-users

* Wojciech Pietron [2006.10.03 12:00]:
> ==================================================
> #!/bin/zsh
> 
> names=(peter ann)
> digits=(one two three four)
> analyze=(names digits)
> 
> for t in $analyze; do
>     for ((i=1; i<=${(P)#t}; i++)); do
>         #No problems with displaying the indirect tables
>         echo ${(P)t}
>     done
> done
> ==================================================
> 
> I have no problems with displaying the contents of the indirect table
> inside of the inner loop but how can I do the following operations there:
> - displaying i-th element of the array;

print -r -- "${(P)${t}[$i]}"

> - setting i-th element of the array.

eval "${t}[$i]=foobar"

HTH,

-- 
JR


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

end of thread, other threads:[~2006-10-03 17:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-03 15:54 Array indirection Wojciech Pietron
2006-10-03 17:25 ` Jean-Rene David

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