Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: pointers and associative maps
- X-seq: zsh-users 19930
- From: Jaromil <jaromil@xxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: pointers and associative maps
- Date: Fri, 27 Feb 2015 15:02:11 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dyne.org; s=mail; t=1425045717; bh=Xv03Kbaaf5KJ2V5jFiQFKe9YrXRJTsKzIlMic6vz/P0=; h=Date:From:To:Subject:References:In-Reply-To:From; b=PEkJj7SVSUqinulLWZQBmBt9ua7BAkPodH9321m+cLp0fsyVqqPyKcjBl0t0yXEhS n2WnLgP9IMZ8Szqzzm457YriRgwT4fdbnRb3wFlMgl6rUQP6zafcNFhp0Lz6mTjoAe PaKwkcoV7zXDKUurtLfs8ERMbaxW0RoPzGVNNa0Y=
- In-reply-to: <20150227124641.GA17275@fork>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- Organization: Dyne.org Free Software Foundry
- References: <20150227120941.GA15885@fork> <20150227124641.GA17275@fork>
third reply to myself, now I'm embarassed. however:
> solved! using ${(Pv)${_map}[$c]}
this solves it only for values in the associative map, not for keys.
So my problem persists and I wonder if there are solutions to this:
use a pointer to an associative map to get out keys from it.
Here a small function to help reproduce the situation
typeset -A mappa
zkv-test() {
mappa+=(key1 value1)
mappa+=(key2 value2)
mappa+=(key3 value3)
_map=mappa
_num="${(P)#_map}"
for c in {1..$_num}; do
print "$c/$_num: ${(Pk)${_map}[$c]} ${(Pv)${_map}[$c]}"
done
}
once launched, it prints:
1/3: 1 value1
2/3: 2 value2
3/3: 3 value3
where I believe it should be:
1/3: key1 value1
2/3: key2 value2
3/3: key3 value3
puzzling enough, after running the function one can do:
print ${${(Pk)_map}[$c]}
from the interactive console, moving the (Pk) modifier inside the inner
brackets, and then the key3 will be printed (or any, according to $c index)
please note that having the (Pk) modifier in the inner brackets when run inside
the function does not work at all, rather indexes single chars in the key/value
retrieved (as mentioned in my first post)
Am I missing something?
thanks for your patience about my cascade posting
ciao
Messages sorted by:
Reverse Date,
Date,
Thread,
Author