g0n cited perlfaq4 thusly:
If you don't care about the order of the elements, you could just
create the hash then extract the keys. It's not important how you
create that hash: just that you use keys to get the unique
elements.
If you do care about the ordering of the input list data,
and the data are simple scalars (typically strings),
then what you want is sometimes termed idempotency:
you want a value to appear only once, the first time is meaningful,
but any occurences after the first appearance need to be removed.
I asked about this
some time ago and (to reiterate the final results
of the discussion that took place there), we came up with the
following technique:
my %seen =(); @unique_array = grep(! $seen{$_}++ , @non_unique_array);
-
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.
|