One and a half passes.
my ($i, %seen) = (0);
my @no_dup =
grep { 2 < push @{$seen{/(pattern)/}}, $i++ }
@with_dup;
@no_dup = map { 2 < @$_ ? $no_dup[$_->[0]] : () } values %seen;
Makes use of the little known return value from
push but probably no more efficient than the two pass solutions due to creation of a lot of anonymous arrays. Hmm.. I can do better..
my ($i, %seen) = (0);
my @no_dup =
grep { -1 != ($seen{/(pattern)/} = exists $seen{$1} ? -1 : $i++) }
@with_dup;
@no_dup = @no_dup{grep $_ != -1, values %seen};
Update: fixed a thinko.
Makeshifts last the longest.
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.