zsh-users
 help / color / mirror / code / Atom feed
From: Jaromil <jaromil@dyne.org>
To: zsh-users@zsh.org
Subject: Re: pointers and associative maps
Date: Fri, 27 Feb 2015 15:02:11 +0100	[thread overview]
Message-ID: <20150227140211.GA18843@fork> (raw)
In-Reply-To: <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



  reply	other threads:[~2015-02-27 14:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-27 12:09 Jaromil
2015-02-27 12:46 ` Jaromil
2015-02-27 14:02   ` Jaromil [this message]
2015-02-27 18:04     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150227140211.GA18843@fork \
    --to=jaromil@dyne.org \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).