* value of a key pointed by (P) ?
@ 2006-09-15 17:47 Marc Chantreux
2006-09-15 17:56 ` Peter Stephenson
0 siblings, 1 reply; 5+ messages in thread
From: Marc Chantreux @ 2006-09-15 17:47 UTC (permalink / raw)
To: zsh-users
Hi all,
typeset -A a
a=(
this is
something special
for you
)
b=a
k=this
print ${${(P)b}[$k]}
i expect 'is', i get 'you'. Why ? how to fix ?
thanks a lot for help.
regards.
mc
--
téléphone : 03.90.24.00.19
courriel : marc.chantreux@ulpmm.u-strasbg.fr
---------------------------------------
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: value of a key pointed by (P) ?
2006-09-15 17:47 value of a key pointed by (P) ? Marc Chantreux
@ 2006-09-15 17:56 ` Peter Stephenson
2006-09-15 20:17 ` Marc Chantreux
2006-09-16 5:47 ` Bart Schaefer
0 siblings, 2 replies; 5+ messages in thread
From: Peter Stephenson @ 2006-09-15 17:56 UTC (permalink / raw)
To: zsh-users
Marc Chantreux <marc.chantreux@ulpmm.u-strasbg.fr> wrote:
> typeset -A a
> a=(
> this is
> something special
> for you
> )
> b=a
> k=this
> print ${${(P)b}[$k]}
>
> i expect 'is', i get 'you'. Why ? how to fix ?
The expression generated by ${(P)b} is passed back as an ordinary array, so
it isn't indexed properly by the $k.
I don't think there's an easy answer; you have to resort to something like
eval print '${'$b'[$k]}'
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: value of a key pointed by (P) ?
2006-09-15 17:56 ` Peter Stephenson
@ 2006-09-15 20:17 ` Marc Chantreux
2006-09-16 5:57 ` Bart Schaefer
2006-09-16 5:47 ` Bart Schaefer
1 sibling, 1 reply; 5+ messages in thread
From: Marc Chantreux @ 2006-09-15 20:17 UTC (permalink / raw)
To: zsh-users
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=utf-8, Size: 623 bytes --]
le 15/09/2006,
Peter Stephenson nous écrivait :
> The expression generated by ${(P)b} is passed back as an ordinary array,
isn't it a bug? do you think it's possible to fix it in future versions
of zsh ?
> so it isn't indexed properly by the $k.
it's clear now ... thanks for explain, Peter
>
> I don't think there's an easy answer; you have to resort to something like
> eval print '${'$b'[$k]}'
i've done it but it isn't as sexy as the way i tried to write.
regards
mc
--
téléphone : 03.90.24.00.19
courriel : marc.chantreux@ulpmm.u-strasbg.fr
---------------------------------------
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: value of a key pointed by (P) ?
2006-09-15 20:17 ` Marc Chantreux
@ 2006-09-16 5:57 ` Bart Schaefer
0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2006-09-16 5:57 UTC (permalink / raw)
To: zsh-users
On Sep 15, 10:17pm, Marc Chantreux wrote:
} Subject: Re: value of a key pointed by (P) ?
}
} le 15/09/2006,
} Peter Stephenson nous écrivait :
} > The expression generated by ${(P)b} is passed back as an ordinary array,
}
} isn't it a bug?
No, it's not. ${(P)b} is "the value of the thing named by the value of
b" and the value of the parameter a is an ordinary array consisting of
all the values of the associative array.
What you want are name references, that is, "the thing named by the
value of b" (note the difference -- missing one "value of"). Zsh
doesn't have those yet, and when it does they probably won't be
implemented via parameter expansion flags.
Also consider:
b="a[$k]"
print ${(P)b}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: value of a key pointed by (P) ?
2006-09-15 17:56 ` Peter Stephenson
2006-09-15 20:17 ` Marc Chantreux
@ 2006-09-16 5:47 ` Bart Schaefer
1 sibling, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2006-09-16 5:47 UTC (permalink / raw)
To: zsh-users
On Sep 15, 6:56pm, Peter Stephenson wrote:
}
} I don't think there's an easy answer; you have to resort to something like
}
} eval print '${'$b'[$k]}'
print ${(e):-'${'$b'[$k}]'}
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-09-16 5:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-15 17:47 value of a key pointed by (P) ? Marc Chantreux
2006-09-15 17:56 ` Peter Stephenson
2006-09-15 20:17 ` Marc Chantreux
2006-09-16 5:57 ` Bart Schaefer
2006-09-16 5:47 ` Bart Schaefer
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).