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

Bug with associative array and P flag?



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