I need to preserve all alphabetic elements of the array but the duplicate numeric elements must be removed. The original array is 45,000+ elements. I am trying to end up with a result like the below (yes, the pipe is required):

20055111|YOUSLAV,YURT,TENWIMPL 20011271|YOUSLAV,WUMARTHE 20011541|YOUSLAV,TENWIMPL 20102741|WEDLOFOU,YOUSLAV,YURT,KUPLYSO,TENWIMPL 20155505|YOUSLAV,YURT,TENWIMPL 20147155|YOUSLAV,KUPLYSO,FRIMA

The original data looked like this:
20055111,YOUSLAV, 20055111,YURT, 20055111,TENWIMPL, 20011271,YOUSLAV, 20011271,WUMARTHE 20011541,YOUSLAV, 20011541,TENWIMPL, 20102741,WEDLOFOU, 20102741,YOUSLAV, 20102741,YURT, 20102741,KUPLYSO, 20102741,TENWIMPL, 20155505,YOUSLAV, 20155505,YURT, 20155505,TENWIMPL, 20147155,YOUSLAV, 20147155,KUPLYSO, 20147155,FRIMA,

I have tried the below but (unfortunately) it removes ALL duplicate elements. I am trying to preserve the alphabetic elements.

sub uniq { my %seen; grep !$seen{$_}++, @_; } my @cert = qw( 20055111 YOUSLAV 20055111 YURT 20055111 TENWIMPL 20011271 YOUSLAV + 20011271 WUMARTHE 20011541 YOUSLAV 20011541 TENWIMPL 20102741 WED +LOFOU 20102741 YOUSLAV 20102741 YURT 20102741 KUPLYSO 20102741 TE +NWIMPL 20155505 YOUSLAV 20155505 YURT 20155505 TENWIMPL 20147155 +YOUSLAV 20147155 KUPLYSO 20147155 FRIMA ); my @filtered = uniq(@cert); print "@filtered\n";

Below is a sample of the file I am trying to work with. I replace all the commas with spaces in my array:

20055111,YOUSLAV, 20055111,YURT, 20055111,TENWIMPL, 20011271,YOUSLAV, 20011271,WUMARTHE, 20011541,YOUSLAV, 20011541,TENWIMPL, 20102741,WEDLOFOU, 20102741,YOUSLAV, 20102741,YURT, 20102741,KUPLYSO, 20102741,TENWIMPL, 20155505,YOUSLAV, 20155505,YURT, 20155505,TENWIMPL, 20147155,YOUSLAV, 20147155,KUPLYSO, 20147155,FRIMA, 20172145,TENWIMPL, 20172175,TENWIMPL, 20175511,FRIMA, 20174117,TENWIMPL, 20175410,TENWIMPL, 20175554,YOUSAID, 20202011,FRIMATEC, 20214475,CIPWOMAT, 20271275,YOUSLAV, 20271275,YURT, 20271275,TENWIMPL, 20217175,YURT, 20217175,KUPLYSO, 20217175,TENWIMPL, 20217177,WEDLOFOU, 20217177,YOUSLAV, 20217177,YURT, 20217177,YURTRN, 20217177,YURTRN, 20217177,TENWIMPL, 20217177,WEDLOFOU, 20217177,YOUSLAV, 20217177,KUPLYSO, 20217177,TENWIMPL, 20217171,YOUSLAV, 20217171,YURT, 20217171,TENWIMPL, 20217171,YOUSLAV, 20217171,YURT, 20217171,TENWIMPL, 20217110,WEDLOFOU, 20217110,YOUSLAV, 20217110,KUPLYSO, 20217110,TENWIMPL, 20217112,YOUSLAV, 20217112,YOUTESSNO, 20217112,YOUTESSNO, 20217507,YOUSLAV, 20217501,WEDLOFOU, 20217501,YOUSLAV, 20217501,TENWIMPL, 20217512,TENWIMPL, 20217517,YOUSLAV, 20217517,FRIMA, 20217517,YOUSLAV, 20217517,YURT, 20217517,TENWIMPL, 20217511,YOUSLAV, 20217511,SYMKIR, 20217511,TENWIMPL, 20217520,WEDLOFOU, 20217520,YOUSLAV, 20217520,TENWIMPL, 20217521,YOUSLAV, 20217521,TENWIMPL, 20217522,WEDLOFOU, 20217522,YOUSLAV, 20217522,CIPWOMAT, 20217522,TENTMIR, 20217522,TENTMIR, 20217555,YOUSLAV, 20217555,YURT, 20217555,TENWIMPL, 20217557,CODNGSPC, 20217774,YOUSLAV, 20217774,KUPLYSO,


In reply to How do I remove duplicate numeric elements of an array and preserve alphabetic elements? by jzelkowsz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.