It was one of the recipies when we did some "Pike cookbook" work.
Title: Multi index Contributor: Martin Nilsson Problem: You have a set of indices into an array and want to create a new array built from the values from the first array.
Solution:
array multiindex(array arr, array ind) { return arr[ind[*]]; }
Discussion:
This is a use for the automap operator that isn't obvious to come up with. To help you make sense of the expression above the expression could be verbalized as "indexing arr with, in turn, all the indices in ind and putting all the result values in an array".
Note that in most cases when this problem appears it is better avoided all together than solved. One typical example is that you have one array with a set of values and several arrays with different sortings, or different (sorted) subsets. In Pike there is no waste of memory to store the actual values in all arrays instead of just pointers into a value array. You'll actually save some by not having a value array.