W
William James
The PerlFAQ says:
----------------------------------------------------------------------------
Here's an example of how to pull out the first word after the
first number on each item, and then sort those words
case-insensitively.
[snip]
which could also be written this way, using a trick that's come to
be
known as the Schwartzian Transform:
@sorted = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_, uc( (/\d+\s*(\S+)/)[0]) ] } @data;
----------------------------------------------------------------------------
This method of sorting is already built in to Ruby. The equivalent
of the above would be:
sorted = data.sort_by{ |x| x[ /\d+\s*(\S+)/, 1 ].upcase }
I wonder if it will be included in Perl 6.
----------------------------------------------------------------------------
Here's an example of how to pull out the first word after the
first number on each item, and then sort those words
case-insensitively.
[snip]
which could also be written this way, using a trick that's come to
be
known as the Schwartzian Transform:
@sorted = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_, uc( (/\d+\s*(\S+)/)[0]) ] } @data;
----------------------------------------------------------------------------
This method of sorting is already built in to Ruby. The equivalent
of the above would be:
sorted = data.sort_by{ |x| x[ /\d+\s*(\S+)/, 1 ].upcase }
I wonder if it will be included in Perl 6.