Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Bug with associative array and P flag?
- X-seq: zsh-workers 19705
- From: Jonathan Hankins <jonathan-hankins@xxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Bug with associative array and P flag?
- Date: Mon, 29 Mar 2004 20:14:40 -0600
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
Hi,
Below are two examples of using the P flag to variable expansion to access an
array indirectly. When using a regular array (foo), this works correctly.
However, when using an associative array in the same way, I get the value of
the first (alphabetically? randomly?) key (animal) regardless of the key I
use. Should the P flag work with the associative array in the same way as it
does with the regular array?
I have tested with 4.2.0, 4.1.1 and 4.0.9 on Debian GNU/Linux.
% typeset -a foo
% typeset -A bar
%
% foo=(this is an array)
%
% bar[color]=red
% bar[animal]=cat
% bar[fruit]=apple
%
%
% ref=foo
% print ${${(P)ref}[1]}
this
% print ${${(P)ref}[2]}
is
% print ${${(P)ref}[3]}
an
% print ${${(P)ref}[4]}
array
%
% ref=bar
% print ${${(P)ref}[color]}
cat
% print ${${(P)ref}[animal]}
cat
% print ${${(P)ref}[fruit]}
cat
%
Just for kicks, this works as expected:
% print ${${(P)ref}}
cat apple red
% print ${${(Pk)ref}}
animal fruit color
% print ${${(Pkv)ref}}
animal cat fruit apple color red
Thanks,
-Jonathan Hankins
Messages sorted by:
Reverse Date,
Date,
Thread,
Author