geektron has asked for the wisdom of the Perl Monks concerning the following question:
it sounds like a job for the Schwartzian Transform, but i'm at a loss on how to build the temp array/hash then reconstruct the original.
the values i need to sort on look like this:
I need to sort the array of hashrefs by color, then by size, but since (obviously) S should come before M ... an alpha or ascii sort won't work. i *think* i need a mapping hash also.size: L, color: White size: M, color: Orange size: M, color: White size: M, color: White size: S, color: Orange size: S, color: White size: Xl, color: Orange size: Xl, color: White size: Xl, color: White
i have the regex to get the values out of the string ... but now, how to apply that into a Schwartzian and reconstruct?
where $2 would be the first sort criteria, $1 the second ... so that i end up with ordering like:my $string = $element->{description}; $string =~ m!\w+:\s(\w+),\s\w+:\s(\w+)!;
size: S, color: Orange size: S, color: White size: M, color: Orange size: M, color: White size: M, color: White size: L, color: White size: Xl, color: Orange size: Xl, color: White
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: complicated sorting issue
by dragonchild (Archbishop) on Apr 09, 2004 at 19:42 UTC | |
by geektron (Curate) on Apr 09, 2004 at 19:49 UTC | |
by dragonchild (Archbishop) on Apr 09, 2004 at 20:13 UTC | |
by Anonymous Monk on Apr 09, 2004 at 20:20 UTC | |
|
Re: complicated sorting issue
by sgifford (Prior) on Apr 09, 2004 at 19:50 UTC | |
|
Re: complicated sorting issue
by Anonymous Monk on Apr 09, 2004 at 19:56 UTC | |
by merlyn (Sage) on Apr 09, 2004 at 20:02 UTC | |
by Anonymous Monk on Apr 09, 2004 at 20:08 UTC | |
by geektron (Curate) on Apr 09, 2004 at 20:34 UTC | |
by Anonymous Monk on Apr 09, 2004 at 20:58 UTC |