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

Re: [MacPerl] efficiency & memory



Carl Johan Berglund wrote:
> 
> If you say
> 
> sort 0..$#ids
> 
> you will get the numbers 0, 1, 2, 3, etc in ascending order, and hence get
> them in the order they were from the beginning. However, if you say
> 
> sort byID 0..$#ids
> 
> the order depends on the byID sorting subrouitine. In Nathaniel's code,
> byID was:
> 
> sub byID {
>     $ids[$a] <=> $ids[$b];
> }
> 
> This thing compares not the numbers themselves, but elements in @ids array.
> If $ids[1] < $ids[0], 1 will come before 0 in the array that is sorted this
> way.
> 
> Any clearer?

Yes it is except in the original posting (if I remember correctly since
I did not save it), wasn't the array:

	@<something>_<something>???

Which would mean that the @id array was not the same array.  So either
the @id array contained a duplicate of the array to be sorted or the
sort routine was sorting the wrong array.  (Unless of course the id
array kept the keys to how the array should be sorted.)

Actually, now that I've thought about it - wasn't it something like:

	@id = @<something>_array[ sort byID 0..$#id ]; ?

And the subroutine was as you presented it.  Would this not mean that
the null array @id (assuming nothing was in the array to begin with)
just not sort?  Or does MacPerl move everything over first before it
sorts everything?

(Like I said - even though I understand what it is that is going on it
is still a rather strange way (to me) of doing this.)

But thanks for the explanation!  :-)

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