- or download this
my @sorted =
map { $_->[0] }
sort { $a->[1] cmp $b->[1] } # or <=>, or $b before $a
map { [$_, f($_)] }
@unsorted;
- or download this
# the first map does this
qw(8 11 9 4 3) --> (
...
[ 4, "vi"],
[ 3, "iii"],
)
- or download this
# the sort does this:
(
...
[ 8, "viii"],
[11, "xi"],
)
- or download this
(
[ 3, "iii"],
...
[ 8, "viii"],
[11, "xi"],
) --> qw( 3 9 4 8 11 )
- or download this
use strict;
use warnings;
...
__END__ # output shown below
3 4 9 8 11
- or download this
my @sorted = sort { f($a) cmp f($b) } @unsorted;
- or download this
*f = sub {
$::count++;
END { print "f() called $::count times\n" };
goto \&Roman::roman;
};
- or download this
use List::Util "shuffle";
my @unsorted = shuffle(1..100);