
dws
Deleted
Jun 11, 2000, 10:06 AM
Post #2 of 3
(146 views)
|
Use a "Schwartzian Transform". The idea is to turn each datum into an anonymous array that contains the initial datum plus some aspect of it (in this case, the leading digit), then sort the anonymous arrays based on the aspect, then turn the anonymous arrays back into the original datum. <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> @data = ("1|foo", "10|baz", "5|bar"); @sorted = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, (split /\|/, $_)[0] ] } @data; print join "\n", @sorted;</pre><HR></BLOCKQUOTE>
|