On 5/28/23 2:05 AM, Martin D Kealey wrote:
On Tue, 23 May 2023 at 23:32, Chet Ramey <chet.ra...@case.edu> wrote:
On 5/22/23 10:56 PM, Martin D Kealey wrote:
For example, if one is filling an array in random order, rather than
progressively adding to the end, then it is useful and makes sense to be
able to ask the array for its highest index.
You can parse the output of ${!array[@]} to get that.
True, but stupidly inefficient for a large array. (If you're inclined to
respond "but this is Shell so nobody cares about performance", please read
my rebuttal in the PS below.)
I suppose that if I had a large array, that I was populating randomly
with sparse elements, and I was interested in the highest-numbered index,
and I deemed the usual way to discover the largest index too inefficient,
I would keep track of that at assignment time.
How about making ${!array[@]:s:n} work in the obvious manner, including
when s=-1 n=1?
I don't generally jam together two different parameter expansions to create
a hybrid one, but if you'd like to take a shot at it, send me what you come
up with.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/