[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] efficiency & memory



At 00.39 +0200 98-08-21, Mark Manning/Muniz Eng. wrote:
>Isn't that supposed to be:
>
>	@sorted = sort byID @master_lines;
>
>instead of
>
>	@sorted = @master_lines[ sort byID 0..$#ids ];
>
>?????

Probably not. This is just an alternative way of sorting, where you sort
the array indices and then rearrange the array by taking a same-length
slice of it.

You know, array slices are parts of arrays:

@array[0,1,2,3] # The first 4 elems of @array.

@array[2,1,0,3] # Same elements, in another order.

In Nathaniel's code, 0..$#ids is an array of the numbers 0, 1, 2, 3,... to
the number of elements in the array, hence an array of all the indices in
the array. By rearranging those indices with sort, and taking the slice,
the array get sorted, sort of.

Cajo.


___Carl_Johan_Berglund_________________________
   Adverb Information
   carl.johan.berglund@adverb.se
   http://www.adverb.se/



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch