Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Associative array ordering and selective unset (Re: Example function)
- X-seq: zsh-workers 5158
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: Re: Associative array ordering and selective unset (Re: Example function)
- Date: Tue, 2 Feb 1999 09:01:18 +0100 (MET)
- In-reply-to: "Bart Schaefer"'s message of Mon, 1 Feb 1999 11:09:19 -0800
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
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@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author