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

Re: [MacPerl] using one array to sort another



On Mon, 28 Jun 1999 cetasix@pop.erols.com wrote:

> I have an array @comp_array which is sorted in the following manner:
> 
> 1
> 1.1
> 1.1.p.1
> 1.1.1
> 1.1.2
> 1.1.3
> 
> I would like to use the above arrangement to sort the following associative
> array called @names
> 
> 1.1.2|||Jeff||Alexander
> 1|||Joe||Alexander
> 1.1.p.1|||Claudia||Alexander
> 1.1|||Nathan||Alexander
> 1.1.3|||Herb||Alexander
> 1.1.1|||Bob||Alexander
> 
> The end result I would like to have is an array @results to be:
> 
> 1|||Joe||Alexander
> 1.1|||Nathan||Alexander
> 1.1.p.1|||Claudia||Alexander
> 1.1.1|||Bob||Alexander
> 1.1.2|||Jeff||Alexander
> 1.1.3|||Herb||Alexander
> 
Create a hash which contains the unsorted data. Then iterate over each
item in your "sort" array, and use that as the key into your hash, writing
the value into a new, sorted data array, prepending the key itself to the
value as you write it.

Arved



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org