Re: Understanding the Schwartzian transform.

by tobyink (Abbot)
 on Jul 22, 2013 at 07:51 UTC ( #1045610=note: print w/replies, xml ) Need Help??

```my @sorted =
map  { \$_->[0] }
sort { \$a->[1] cmp \$b->[1] } # or <=>, or \$b before \$a
map  { [\$_, f(\$_)] }
@unsorted;
```
```# the first map does this
qw(8 11 9 4 3) --> (
...
[ 4, "vi"],
[ 3, "iii"],
)
```
```# the sort does this:
(
...
[ 8, "viii"],
[11, "xi"],
)
```
```(
[ 3, "iii"],
...
[ 8, "viii"],
[11, "xi"],
) --> qw( 3 9 4 8 11 )
```
```use strict;
use warnings;
...

__END__ # output shown below
3 4 9 8 11
```
```my @sorted = sort { f(\$a) cmp f(\$b) } @unsorted;
```
```*f = sub {
\$::count++;
END { print "f() called \$::count times\n" };
goto \&Roman::roman;
};
```
```use List::Util "shuffle";
my @unsorted = shuffle(1..100);
```

Create A New User
Node Status?
node history
Node Type: note [id://1045610]
help
Chatterbox?
 [james28909]: i think im good [james28909]: i just watched a youtube video [karlgoethebier]: james28909: Did you look on CPAN? [james28909]: lol [karlgoethebier]: james28909: Super Search here ? [karlgoethebier]: james28909: No kidding

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2017-05-25 16:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My favorite model of computation is ...

Results (187 votes). Check out past polls.