[ale] Re: sort using perl
Greg Sabino Mullane
greg at turnstep.com
Tue Dec 18 10:40:03 EST 2001
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
> Does anybody know a quick and dirty way to sort by the third letter...
Perl is particularly good at this sort of thing:
my @sorted =
map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [$_, lc substr($_,2)] } @list;
This is very quick as in "time to sort a large list."
If you want quick as in "quick to type" (but much slower to run):
for (sort { lc substr{$a,2} cmp lc substr($b,2)} @list) {
print;
}
All of this depends on the nature and size of your data of course:
for the above, I'm assuming that case does not matter, all sorting
is alphabetic, and the characters after the third are also significant
as far as the sorting goes.
Greg Sabino Mullane
greg at turnstep.com
PGP Key: 0x14964AC8 200112181033
-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html
iD8DBQE8H2NGvJuQZxSWSsgRAsbwAKCC8toiOkV3JXvF4kI/t6FShn70TACgqvzZ
w3lAYe7nsY73YzK1EaxZe30=
=j5/U
-----END PGP SIGNATURE-----
---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be
sent to listmaster at ale dot org.
More information about the Ale
mailing list