Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Keying arrays to names: is there an array of arrays?



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