Fuzzy Frog has asked for the wisdom of the Perl Monks concerning the following question:
I have a moderately complicated data structure I want to sort according to somewhat esoteric rules. This seems to be exactly what Data::Sorting was designed for. I am having trouble figuring out how to apply the module tp my specific problem, though. I have read the docs on CPAN several times, but I always end up mildly confused about exactly what to do.
The subroutine that needs the sorted data is passed a reference to a hash. The keys of the hash are arbitrary numbers, and the values are arrays that hold information about a particular person. More precisely, the hash has this structure:
{number_1 => [last_name1, first_name1, middle_name1, other_stuff1], number_2 => [last_name2, first_name2, middle_name2, other_stuff2], . . . number_N => [last_nameN, first_nameN, middle_nameN, other_stuffN], }
I want to sort the keys (number_1 ... number_N) by the alphabetical ranking of the name in that key's value. As usual, the priority is last_name > first_name > middle_name. Nothingness should sort before everything else, and hyphens should sort before "A".
Since the previous paragraph ended up more confusing than I'd hoped, I have an example. Suppose I want to sort the keys of this hash:
(spaces added for clarity) {1 => [Frog, Fuzzy, A, other_stuff], 2 => [Frog, Fuzzy, , other_stuff], 3 => [Toad, Zola, Q, other_stuff], 4 => [Frogger, Anthony, J, other_stuff], 5 => [Frog-Toad, Berl, G, other_stuff]}
The keys should end up in the order (2, 1, 5, 4, 3)
I would really like to get this working within a week or so. Any help would be greatly appreciated.
P.S. I do not mean to imply that simonm's docs are in any way deficient. I'm sure the problem lies entirely with me.
-- FF
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Data::Sorting
by davido (Cardinal) on May 27, 2004 at 16:23 UTC | |
|
Re: Data::Sorting
by Limbic~Region (Chancellor) on May 27, 2004 at 16:26 UTC | |
|
Re: Data::Sorting
by duff (Parson) on May 27, 2004 at 16:29 UTC | |
by tye (Sage) on May 27, 2004 at 17:19 UTC | |
by BrowserUk (Patriarch) on May 27, 2004 at 18:16 UTC | |
|
Re: Data::Sorting
by simonm (Vicar) on May 28, 2004 at 00:29 UTC |