Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: print entire array *with* subscript?



* Andrey Borzenkov <arvidjaar@xxxxxxx>:
> but I really fail to see when it can be useful. After all to print all array 
> indices (ignoring KSH_ARRAYS for the moment):
> 
> {pts/0}% echo {1..$#foo}
> 1 2 3

The usefulness is a little more obvious when
printing both indices and values. 

The original idea was this.  Suppose I have a list
of files in an array and I want to select one to
do a command on.

files=(foo.h foo.c bar.h bar.c)

It would be nice to be able to do this:

print ${(k)files}
1 foo.h 2 foo.c 3 bar.h 4 bar.c

instead of:

for f in {1..$#files}; do 
  print $f ${files[$f]};
done

Not a big deal. Just asking because that's what I
thought the documentation meant.

Now that I wrote all this I realize I could just
use 'select'...

-- 
JR



Messages sorted by: Reverse Date, Date, Thread, Author