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 13:46:41 +0100	[thread overview]
Message-ID: <20150227124641.GA17275@fork> (raw)
In-Reply-To: <20150227120941.GA15885@fork>


whopsie

On Fri, 27 Feb 2015, Jaromil wrote:

> The problem arises when I want to iterate through values, because using
> a pointer modifier (P) and key/value modifiers (k)|(v) I get out only
> the first char of the map field, not the whole string. I guess this is
> related to the scoping of modifiers? here is how I do it:
> 
> # _map is the variable holding the name of the associative map
> 
> _num="${(P)#_map}"
> for c in {1..$_num}; do
>     sysread -o 1 <<EOF >> $_path
> $_map+=("${${(Pk)_map}[$c]}" "${${(Pv)_map}[$c]}")
> EOF
> 
> 
> presuming that ${${(Pk)_map}[$c]} and ${${(Pv)_map}[$c]} should give in result
> the full string, but instead they return the first char of the string, as if
> the map index does not apply to the map but to the string object, so to say.

solved! using ${(Pv)${_map}[$c]}

and sorry for the noise. I was confused by the fact that the code above
in a function was not giving the same result as: print ${${(Pv)_map}[$c]}
This might be something to look into, basically the automatic scoping
changes.

however the formula above is the right solution, I guess it has a more
explicit scoping of modifiers.

again thanks for ZSh, its an awesome portable tool.  I'll do my best to
contribute to it in some future, perhaps some extensions based on
libraries I've written.

ciao



  reply	other threads:[~2015-02-27 12:46 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 [this message]
2015-02-27 14:02   ` Jaromil
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=20150227124641.GA17275@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).