Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Keying arrays to names: is there an array of arrays?
- X-seq: zsh-users 10320
- From: "Johann 'Myrkraverk' Oskarsson" <johann@xxxxxxxxxxxxxx>
- To: ZSH Users <zsh-users@xxxxxxxxxx>
- Subject: Re: Keying arrays to names: is there an array of arrays?
- Date: Sun, 28 May 2006 02:34:10 +0000
- In-reply-to: <060527151044.ZM25448@xxxxxxxxxxxxxxxxxxxxxx> (Bart Schaefer's message of "Sat, 27 May 2006 15:10:44 -0700")
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <m33bewj29n.fsf@xxxxxxxxxxxxxxxxxx> <44771E3E.9070102@xxxxxxxxxxxxxxxxxx> <200605261540.k4QFeReG007573@xxxxxxxxxxxxxx> <m3wtc7gu80.fsf@xxxxxxxxxxxxxxxxxx> <060527151044.ZM25448@xxxxxxxxxxxxxxxxxxxxxx>
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> writes:
> I'll assume you mean the *associative* array (hash) name.
Yes, thank you very much.
> A function to do the assignment isn't too terrible, though there are
> scoping issues -- either the hash already has to exist, or you can
> only create it in the global scope by using typeset -g:
The following version also works with IFS="" (I guess it will work
with IFS equal to something sensible too).
mapassign() {
local h=$1 k=$2
shift 2
set -- ${(j: :q)*}
typeset -gA $h
typeset -g $h\[$k\]="$*"
}
> A function to read back the value is a bit trickier. What do you want
> to do with the array once you have it? A common fallback would be to
> stuff it in $reply:
Same with this one:
mapread() {
set -- $1\[$2\]
reply=( ${(s: :Q)${(z)${(P)1}}} )
}
> Incidentally:
>
> } I classify Outlook mail as spam, use something else.
>
> Someone asking for assistance has no right to dictate terms. You want
> my help, you take it the way I send it. I don't happen to use Outlook,
> but next time I see something like this, I just won't answer.
That isn't meant for mailing lists, but for private messages. I've
modified my tag line a bit, but it's also your prerogative not to
answer.
--
johann myrkraverk com (you know the drill with the @ and .)
I classify Outlook mail as spam, please use something else for private
messages.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author