umasuresh has asked for the wisdom of the Perl Monks concerning the following question:
I am expecting the sorted array to be in this order:use strict; my @unsorted = ( '864278_864377', '864518_864703', '851171_851270', '855398_855579', '856258_856357', '861015_861139', '866387_866549', '791806_792296', '1088806_1082296', ); my @sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [ $_, ( split(/\_/, $_) )[0] ] } @unsorted; print join ("\n",@sorted);
Instead I am getting this:791806_792296 851171_851270 855398_855579 856258_856357 861015_861139 864278_864377 864518_864703 1088806_1082296
I just can't figure out how to fix this! Thanks much for your input! UPDATE: I fixed it by using <=> numeric sort!1088806_1082296 791806_792296 851171_851270 855398_855579 856258_856357 861015_861139 864278_864377 864518_864703 866387_866549
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sort an array using the Schwartzian transform
by Anonyrnous Monk (Hermit) on Jan 21, 2011 at 17:39 UTC | |
|
Re: Sort an array using the Schwartzian transform
by toolic (Bishop) on Jan 21, 2011 at 19:49 UTC | |
|
Re: Sort an array using the Schwartzian transform
by JavaFan (Canon) on Jan 21, 2011 at 20:01 UTC | |
by salva (Canon) on Jan 21, 2011 at 20:35 UTC | |
|
Re: Sort an array using the Schwartzian transform
by ikegami (Patriarch) on Jan 21, 2011 at 18:27 UTC | |
|
Re: Sort an array using the Schwartzian transform
by umasuresh (Hermit) on Jan 21, 2011 at 20:59 UTC |