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

Re: printing arrays and index



On Jul 22,  7:08pm, zzapper wrote:
} Subject: printing arrays and index
}
} I'm using
} 
} print -C 1 $filessubject

I was sort of puzzled by why that was suggested.  "print -l" (that's a
lowercase L, not a one) has the same effect, and works in a lot more
versions of zsh (the -C option is a very recent addition).
 
} I know want to precede each array entry with it's index number 1,2,3, etc
} 
} how do?

The most obvious way is:

	print -l $filessubject | cat -n

But something like this works too:

	i=0 eval print -l '$((++i))\ '${(q)^filessubject}

If you use 'setopt ksharrays' then change that to $((i++)).



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