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

Re: value of a key pointed by (P) ?



Marc Chantreux <marc.chantreux@xxxxxxxxxxxxxxxxxx> 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@xxxxxxx>                  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



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