zsh-users
 help / color / mirror / code / Atom feed
* pointers and associative maps
@ 2015-02-27 12:09 Jaromil
  2015-02-27 12:46 ` Jaromil
  0 siblings, 1 reply; 4+ messages in thread
From: Jaromil @ 2015-02-27 12:09 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1692 bytes --]


dear Zsh people,

I'm an old-time (ab)user of ZSh (started using it back 15yrs ago on
NetBSD), but this is the first time I interact with your lists since
actually I never needed to, your documentation is too good :^).
However, long due contact. Big up for ZSh release v5 BTW.

I'm puzzled by a problem I encounter using pointers and associative
maps. I want to use a variable as pointer for an associative map, then
iterate through the map to get all its values, for saving it to a file
and implement a simple load/save key/value store.

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.

Am I missing something here? Does anyone has clues?

many thanks!

-- 

Jaromil, Dyne.org Free Software Foundry (est. 2000)
We are free to share code and we code to share freedom
GPG: 6113 D89C A825 C5CE DD02  C872 73B3 5DA5 4ACB 7D10

ZShaolin - Power console terminal for Android
https://play.google.com/store/apps/details?id=org.dyne.zshaolin
Free binaries for ZSh developers, just ask me privately!


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 1513 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-02-27 18:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-27 12:09 pointers and associative maps Jaromil
2015-02-27 12:46 ` Jaromil
2015-02-27 14:02   ` Jaromil
2015-02-27 18:04     ` Bart Schaefer

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).