From mboxrd@z Thu Jan 1 00:00:00 1970 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes Date: Tue, 2 Feb 1999 09:01:18 +0100 (MET) Message-Id: <199902020801.JAA08446@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk In-reply-to: "Bart Schaefer"'s message of Mon, 1 Feb 1999 11:09:19 -0800 Subject: Re: Associative array ordering and selective unset (Re: Example function) X-Mailing-List: 5158 Bart Schaefer wrote: > (Note that I moved the (qQ) into the subscript flags, which is probably > where it really has to be. And I still hope for a better letter.) > > Now change the assignment a little: > > map=('*.(gz|Z)' ': 1; zcat > '*.bz2' ': 2; bzip2 -dc' > '*.bz' ': 3; bzip -dc' > '*' ': 4; <') > > Now we can use the (o) substitution flag like so: > > eval ${${(o)map[(Q)$argv[i]]}[1]} '$argv[i]' > > That says "find all the values for which the key is a pattern that matches > $argv[i], sort them in ascending order, take the first one, and evaluate > it as a command with argument $argv[i]." By embedding the "preferred" > ordering in the value as a leading ":" command, we're assured of always > getting the most-specific match. Hmm, I like this. For bigger arrays one would have to use `01' and so on, but this should be acceptible. Bye Sven -- Sven Wischnowsky wischnow@informatik.hu-berlin.de