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

Re: PATCH: 3.1.5 - sample associative array implementation



"Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx> writes:

> On Nov 11,  3:00pm, Timothy Writer wrote:
> } Subject: Re: PATCH: 3.1.5 - sample associative array implementation
> }
> } In ksh93 associative arrays are declared using "typeset -A".
> 
> This could easily be mimicked.

Good.

> } They use the
> } same syntax as indexed arrays, e.g. "foo[bar]=baz"; the text within [] is
> } subject to variable expansion and whitespace counts.
> 
> Hrm.  Zsh currently can't handle whitespace inside the [ ]; and I'm not
> sure the paramtab implementation I did will work with keys that aren't
> parsable as "identifier".
> 
> Otherwise this is good.
> 
> How can you (or can you not) assign to multiple elements simultaneously?

I don't know, I don't think you can.  Unfortunately, I'm not a ksh93 expert,
I just paraphrased the above info from the ksh93 reference in "Desktop Korn
Shell Graphical Programming".

> } The following special notation is used to get all keys:
> } 
> }     "${!arrayname[@]}"
> 
> Exactly what about that is the special notation?  The `!'?  Does ksh93

I guess so, "special" is the book's term.

> recognize other special characters in that position?  Is there any way
> to get both the keys and the values in a single expansion?

As far as I can tell, only "!" and (of course) "#" are "special" in that
position.  However, "${!variable}" is also special syntax for name reference
variables, e.g.:

    B=2
    nameref A=B
    print $A		# prints: 2
    print ${!A}		# prints: B

Does zsh have namerefs?

I don't think there's a way to get both keys and values in a single
expression.

-- 
Tim Writer                                              Tim.Writer@xxxxxxxxxx
FTL Solutions Inc.
Toronto, Ontario, CANADA



Messages sorted by: Reverse Date, Date, Thread, Author