For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > August 2005 > Schwartzian Transform built-in to Perl 6?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Schwartzian Transform built-in to Perl 6?
William James

2005-08-28, 7:56 am

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.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com