Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: Re: Associative array ordering and selective unset (Re: Example function)
- X-seq: zsh-workers 8259
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: Re: PATCH: Re: Associative array ordering and selective unset (Re: Example function)
- Date: Thu, 14 Oct 1999 16:15:40 +0000
- In-reply-to: <991014150755.ZM21454@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <199910141425.QAA16346@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> <991014150755.ZM21454@xxxxxxxxxxxxxxxxxxxxxxx>
On Oct 14, 3:07pm, Bart Schaefer wrote:
} Subject: Re: PATCH: Re: Associative array ordering and selective unset (Re
}
} } scanparamvals(HashNode hn, int flags)
} } {
} } + if (!(prog = patcompile(tmp, 0, NULL)) || !pattry(prog, scanstr))
} } + return;
}
} It just seemed so unpleasant to recompile the pattern for every key ...
I should probably clarify what I mean by that. In another post, I wrote:
map=(
'(*.(gz|Z)) zcat'
'(*.bz2) bzip2 -dc'
'(*.bz) bzip -dc'
'(*) <'
)
eval 'for i do case $i in' ${(j( $i;; ))map} '$i;; esac done'
Note that with this trick, all the patterns get compiled once (when the
`case' is parsed) and then we can compare every $i to the "keys" without
recompiling any patterns.
Thus the above is going to be significantly more efficient than:
typeset -A map
map=(
'(*.(gz|Z))' 'zcat'
'(*.bz2)' 'bzip2 -dc'
'(*.bz)' 'bzip -dc'
'(*)' '<'
)
for i do eval $map[(k)$i] $i; done
But this is not to suggest we shouldn't keep Sven's patch.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Messages sorted by:
Reverse Date,
Date,
Thread,
Author