Assuming you mean sorting normally:
sub beautify
{
my %stuff;
@stuff{@_} = undef;
return sort keys %stuff;
}
so that:
print join ' ',beautify(qw(h e l l o w o r l d)); # prints "d e h l o
+r w"
print join ' ',beautify(qw(b u m b l e b e e)); # prints "b e l m u"
If you want it sorted by frequency increasing:
sub beautify
{
my %stuff;
$stuff{$_}++ for(@_);
return sort { $stuff{$a} <=> $stuff{$b} } keys %stuff;
}
so that:
print join ' ',beautify(qw(h e l l o w o r l d)); # prints "e w r h d
+o l"
print join ' ',beautify(qw(b u m b l e b e e)); # prints "m u l e b"
You can, of course, reverse the result if you want it highest-frequency-first.
Hope this helps.
Update: Rrgh -- someone else always posts first while I'm typing my reply...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.