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

Re: PATCH: 3.1.5 - sample associative array implementation



Bruce Stephens <b.stephens@xxxxxxxxx> writes:

> Peter Stephenson <pws@xxxxxxxxxxxxxxxxx> writes:
> 
> > This can probably be fixed in a perl-like fasion by adapting
> > setarrvalue(), which should be reasonably painless, though I haven't
> > looked at the details yet.  One question is whether
> >   hash=(key1 val1 key2 val2)
> > replaces the array entirely, or just adds/replaces those elements.  In
> > the former case it's difficult to think of a way of replacing multiple
> > elements at once; maybe another new typeset flag.
> 
> What does ksh93 provide in the way of associative array functionality?
> (I don't have it installed at work, so I can't look it up right not.)

In ksh93 associative arrays are declared using "typeset -A".  They use the
same syntax as indexed arrays, e.g. "foo[bar]=baz"; the text within [] is
subject to variable expansion and whitespace counts.  The following special
notation is used to get all keys:

    "${!arrayname[@]}"

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



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