Since you didn't say you needed to sort anything, I'm not sure what use you'd have for cmp and the special $a and $b variables. Finding unique values is straightforward enough: assign them to a hash as its keys, and then extract the keys. Since hash keys are guaranteed to be unique, any assigned multiple times will still only exist once.
my @list = qw(a b c d e a a b c d f g); # list with some duplicates
my %h;
map { $h{$_} = 1 } @list;
print for sort keys %h; # sorting for clarity's sake
#output
abcdefg
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|