Yesterday, I wanted to get the output from "ls -l some_file" and pull out just the file size and the file name. As I start writing this, I realise, of course, that I'd have been better off just using the File#size method, but I still think the issue I hit is interesting.

I did something like:

   listing = `ls -l #{path}`.split(/\s+/)

so I had the fields from "ls" as an array of strings.

What I then wanted to do was pull out items 4 and 8 (the size and filename) into a new two-element array. I half expected to be able to do that via:

   data = listing[[4, 8]]

but that doesn't work.

Someone will probably tell me there's an easy way to achieve this.  Please feel free to do so.

However, I think it would be nice if the indexing operator for Array, and maybe Hash, or perhaps anything Enumerable, would accept an array as parameter and return another array containing the corresponding items, to allow for non-contiguous selections.

I haven't really thought it through in the case of hashes. Perhaps in that case, one would want to get back a new hash, although I can't imagine that.

Anyway, just a thought.

Cheers,

Harry O.