Perl 5:
@sorted = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [$_, foo($_)] }
@unsorted;
Perl 6:
@sorted = @unsorted.sort: { .uc };
I'm willing to claim that Perl 6 makes this a bit more readable, in spite of the smoke, mirrors and curtains.
Read more about the Schwartzian Transform in Wikipedia.
2 comments:
The Perl5 version is more general - it uses 'foo' as the transformation - while the Perl6 version uses 'uc'.
True, a better example would use something else than .uc.
Post a Comment