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

Re: associative array questions



On Tue, Dec 13, 2022 at 8:12 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> On 2022-12-12 20:39, Bart Schaefer wrote:
> >
> > % : ${(P)list::="tea for two"}
> > %
>
> What's being modified is an array
> and the above method is interfering

You missed where I said "if [$list in this case] names an array, you
can only assign to the entire array"?  Or else you've actually got
  list="${1}[2]"
somewhere you're not showing us.

> local list=$1    # function takes name of array as argument.
>
> eval 'list=( "${(@M)list:#(#i)*$SEARCHBUF*}" )'     # filter the array.

That second line isn't doing anything like what you want.  You don't
have the (P) flag in there anywhere to use the value of $list as a
parameter name, and you're just assigning that back to $list instead
of to the name from $1.  The eval accomplishes nothing because the
whole thing being eval'd is in single quotes to begin with; you might
as well drop both the single quotes and the word eval.

set -A $list "${(P@M)list:#(#i)*$SEARCHBUF*}"

is what Roman is driving at.




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