Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Tip of the day: (@)...[(R)...] is equal to (@M)...:#... and faster by 18-21%
- X-seq: zsh-users 22016
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- Subject: Re: Tip of the day: (@)...[(R)...] is equal to (@M)...:#... and faster by 18-21%
- Date: Fri, 21 Oct 2016 09:20:27 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=8esddEFLaWZMP/Z5KBmIBatnZfFFCXyM/ef/4ZujQ6Q=; b=QYjs8I9iDPLyV2ThZh9cdffIX3xWkbKCE0HZ+81ccPGJsm4YRGaWStHzbWdK6cv146 zNzwTo9owLbLRZxlZa26n6p8UlqCuiKpjqTwxDXd/Nvv0MLErlKUlFtfJdnhizqQHual f77doaSeEsb6UZRXgY9iivh3UjrFHUipBYG3Knam+mwfUzqs8yTuIakoW/6P+pkkTJQn 7jNp12nHinW9TCrEITbLMLRUPHHUh1F3koubWGERaD4UR70NymlImDN7irXkx7d/Qv3X i0i0noFu4MawP2Or/dKf7yaa80Lnr7mhbKYJ9rSR/TH/VBdi9VuD0tTr7L34LKVWg3Z0 oPZg==
- In-reply-to: <536851559.167591.1477040396961@mail.yahoo.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <536851559.167591.1477040396961.ref@mail.yahoo.com> <536851559.167591.1477040396961@mail.yahoo.com>
On Oct 21, 8:59am, <psprint@xxxxxxxxx> wrote:
}
} found=( "${(@M)history:#(#i)*$~search_pattern*}" )
}
} can be replaced by:
}
} found=( "${(@)history[(R)(#i)*$~search_pattern*]}" )
}
} I wonder if there are there any pitfalls in such replacement?
There are some differences in the way the pattern may be interpreted
when it appears inside a subscript expression. There is an entire
section of the documentation (15.2.4 in "info" or HTML docs) devoted
to explaining this. One paragraph in particular applies here:
A last detail must be considered when reverse subscripting is
performed. Parameters appearing in the subscript expression are
first expanded and then the complete expression is interpreted
as a pattern. This has two effects: first, parameters behave as
if GLOB_SUBST were on (and it cannot be turned off); second,
backslashes are interpreted twice, once when parsing the array
subscript and again when parsing the pattern. In a reverse
subscript, it's necessary to use _four_ backslashes to cause a
single backslash to match literally in the pattern. For complex
patterns, it is often easiest to assign the desired pattern to a
parameter and then refer to that parameter in the subscript, because
then the backslashes, brackets, parentheses, etc., are seen only
when the complete expression is converted to a pattern. To match
the value of a parameter literally in a reverse subscript, rather
than as a pattern, use `${(q)NAME}' to quote the expanded value.
So in your example you don't need "$~search_pattern", the expansion is
always interpreted as a pattern. I think the literal match advice in
the final sentence could preferentially be ${(b)...} nowadays; there
are a couple of things about the array subscripting doc that might
need update.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author