>>>>> "RLS" == Randal L Schwartz <[EMAIL PROTECTED]> writes:
RLS> sort { $a/$b expression } { transforming expression, glued with $_ } @list
RLS> so $a->[0] is guaranteed to be the original element, and the list-return
RLS> value of the second block becomes $a->[1]... $a->[$#$a].
RLS> So, to sort case insensitive (bad example :):
RLS> @sorted = sort { $a->[1] cmp $b->[1] } { uc } @list;
RLS> or to sort on GCOS and then username of password lines:
RLS> @sorted = sort { $a->[5] cmp $b->[5] or $a->[1] cmp $b->[1] }
RLS> { split /:/ } `cat /etc/passwd`;
RLS> That captures the canonical ST pretty well, where $a->[0] is always
RLS> the original element.
what everyone is missing in this thread, is that the real and sometime
tricky work is in key extraction and not the map/sort/map. there is no
easy way to describe how to extract multiple keys in the correct order
and then how to do the proper (ascending/descending, string/numeric)
comparisons on them. there are too many possibilities. i explored this
in depth as i designed the Sort::Records module. i had to invent a mini
language to describe all the possible key extractions and
comparisons. think along the lines of getopt::long but more powerful and
you can see the issues. try to describe how to extract this without
using perl code:
(split( ':', $rec->[2]{foo} ))[2]
and sort that numerically in descending order.
now add 2 more keys.
this would have to be a proper module and not a builtin op. there is no
reason to make this built in.
uri
--
Uri Guttman --------- [EMAIL PROTECTED] ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com