From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-users@sunsite.dk
Subject: Re: Backticks and other tricks
Date: Wed, 28 Mar 2001 11:00:44 +0200 (MET DST) [thread overview]
Message-ID: <200103280900.LAA06786@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: Mario Lang's message of 28 Mar 2001 09:22:03 +0200
Mario Lang wrote:
> Can anyone cast some light on the following questions
> regarding the code below:
> 1. Why does ${(P)...[...]} not work with subscripts of the
> array? (in fucntion argsargs).
`array', that's the point. The ${(P)1} yields an array (a *normal*
array, not an associative array). On normal arrays the subscripts of
`[ef1]' etc. are used as mathematical expressions and since there
aren't any variables with those names, mathematical evaluation gives
the value `0' (zero) as subscripts, so one always gets the first
element in the array.
Currently I don't see a solution other than just not using an
associative array at all, e.g. by prepending the `keys' to the
strings:
# No need for backslashes here...
filters=(
ef1:"Resonant bandpass filter":"center frequency":Hz:"width":Hz
ef3:"Resonant lowpass filter":"cutoff frequency":Hz:resonance::gain:
ef4:"Resonant lowpass filter (3rd-order, 36dB)":"cutoff frequency":Hz:resonance:
efa:"Allpass filter":"delay":samples:"feedback":percents
efb:"Bandpass filter":"center frequency":Hz:"width":Hz
efc:"Comb filter":"delay":samples:"radius":0-1
efh:"Highpass filter":"cutoff frequency":Hz
efi:"Inverse comb filter":"delay":samples:"radius":0-1
efl:"Lowpass filter":"cutoff frequency":Hz
efr:"Bandreject filter":"center frequency":Hz:"width":Hz
efs:"Resonator (resonating bandpass filter)":"center frequency":Hz:"width":Hz\
)
argsargs () {
for i in ${(P)1}; do
print -- "*-${i%%:*}[${${i#*:}%%:*}]: :->${i%%:*}"
done
}
> 2. Why does the inclusion trick with backticks not
> work (`argsargs filters`). Actually _arguments complains
> about not being able to parse this option.
The backticks make the words in the output of argsargs be split at
white spaces. One solution would be to set IFS (deprecated) or use
the standard expression for splitting process outputs into lines:
${(f)"$(argsargs filters)"}
The quoting around the $(..) makes it return the complete output as
one (unaltered) string. The (f) flag splits that at newlines into
array elements.
But anyway I would suggest not using process substitution if it can be
avoided (always an extra process). And since the options don't change
it can be cached without any harm. E.g.:
if (( ! $+_ecasound_opts )); then
local filters i
filters=(
...
)
_ecasound_opts=()
for i in $filters; do
_ecasound_opts=($_ecasound_opts "*-${i%%:*}[${${i#*:}%%:*}]: :->${i%%:*}")
done
fi
_arguments \
$_ecasound_opts \
... # other options
To -workers: that the ${(P)1} thing doesn't work is ugly, isn't it?
Bye
Sven
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
next reply other threads:[~2001-03-28 9:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-03-28 9:00 Sven Wischnowsky [this message]
2001-03-28 15:41 ` Bart Schaefer
2001-03-28 18:06 ` Thomas Köhler
2001-03-28 23:56 ` Andre Pang
2001-03-29 3:57 ` Bart Schaefer
-- strict thread matches above, loose matches on Subject: below --
2001-03-28 7:22 Mario Lang
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=200103280900.LAA06786@beta.informatik.hu-berlin.de \
--to=wischnow@informatik.hu-berlin.de \
--cc=zsh-users@sunsite.dk \
/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).