zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: associative array questions
Date: Tue, 13 Dec 2022 14:47:00 -0800	[thread overview]
Message-ID: <f1e85546-04ab-96d5-e280-5dc79ab96400@eastlink.ca> (raw)
In-Reply-To: <CAN=4vMrb_rUfKysnwNZ_MK12NsemohFwMcP-peXfzToAfWF6Og@mail.gmail.com>


On 2022-12-13 12:06, Roman Perepelitsa wrote:
> `set` is a builtin (not a reserved word), so you use it like a normal
> command. Your first email in this thread used it correctly. You can
> also refer to `man zshbuiltins` for documentation.

Nuts, I didn't even consider the problem being the equal sign. One gets 
used to using it in assignment, it looks strange without it.  But yes, 
referring back, I see the mistake.

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

... that seems to be working.  BTW I know it's a builtin and it seems to 
me I used it like a normal command even if mistakenly, how not?

Bart:

> You missed where I said "if [$list in this case] names an array, you
can only assign to the entire array"?

It's nothing but the contents of a file broken down into lines. Yes, I'm assigning the whole thing.  This little piece of ... ah, that's where the confusion comes in -- at this juncture I'm not worried about the entire A-A, just the data array, namely the contents of a file.  So I suspect we're talking apples and oranges.  Subtle change in the topic, pardon! Anyway ... :

> eval 'list=( "${(@M)list:#(#i)*$SEARCHBUF*}" )'     # filter the array.

> That second line isn't doing anything like what you want.  

But it does work perfectly. Remembering of course that there could be some lurking gotcha, but it *seems* fine.

> 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.

Can't say much, only to report that it does work. If I drop the eval and the outer quotes it does nothing, the original array is not changed. As I think I understand it, the second "list" simply becomes the name of the source array and, as I said, eval 'just does it' -- accesses the named array via it's name exactly as I'd intuitively want it to do.  So the '(P)' isn't needed.  Seems so, anyway. But I've been known to completely misunderstand things.

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

is what Roman is driving at.

Right, as above, I ... ah ... well maybe I didn't get it perfect, I 
don't have the '(P@M)' just '(P)' ... but so far so good. Once I dropped 
the equal sign I got it right the first time.





  reply	other threads:[~2022-12-13 22:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-11 17:39 Ray Andrews
2022-12-11 19:53 ` Bart Schaefer
2022-12-11 20:51   ` Ray Andrews
2022-12-11 21:41     ` Bart Schaefer
2022-12-11 22:37       ` Ray Andrews
2022-12-12  1:52         ` Bart Schaefer
2022-12-12  3:09           ` Ray Andrews
2022-12-13  3:31       ` Ray Andrews
2022-12-13  4:39         ` Bart Schaefer
2022-12-13 16:11           ` Ray Andrews
2022-12-13 16:22             ` Roman Perepelitsa
2022-12-13 20:00               ` Ray Andrews
2022-12-13 20:06                 ` Roman Perepelitsa
2022-12-13 22:47                   ` Ray Andrews [this message]
2022-12-13 23:06                     ` Bart Schaefer
2022-12-14  1:08                       ` Ray Andrews
2022-12-13 21:18             ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f1e85546-04ab-96d5-e280-5dc79ab96400@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).