Decorate-sort-undecorate idiom: Difference between revisions

Content added Content deleted
(Added C++ solution)
imported>Tybalt89
Line 786: Line 786:
│ 6 │ chrestomathy │
│ 6 │ chrestomathy │
╰───┴──────────────╯
╰───┴──────────────╯
</pre>

=={{header|Perl}}==
<syntaxhighlight lang="perl">#!/usr/bin/perl

use strict; # https://rosettacode.org/wiki/Decorate-sort-undecorate_idiom
use warnings;
use List::AllUtils qw( nsort_by );

my @list = ("Rosetta", "Code", "is", "a", "programming", "chrestomathy", "site");
print "@list\n";

my @sortedlist = nsort_by { length } @list;
print "@sortedlist\n";</syntaxhighlight>
{{out}}
<pre>
Rosetta Code is a programming chrestomathy site
a is Code site Rosetta programming chrestomathy
</pre>
</pre>