As ambrus noted, your solution, of appending some extra text, is at the mercy of characters at the end making the data. One solution, then, would be to scan the data to select the suffix that already does not exist in data.

Thinking out loud ... or, perhaps use (a heap data structure along w/ a count of each element which would then translate to) a priority list. That does not exactly make each element to be unique as presented in OP, but allows to define uniqueness in other way. That seems, however, quite heavy when we already can use %seen (populated inside the loop) instead of throwing it away. Hmm ...

Addendum, Oct 6,2005: I was thinking of priority value as a count of each string. If there are only few multiplcates, a priority list will be pointless. Using a heap will give you elements in sorted way (meaning lots of comparisons) even if sorting is not a requirement. So i would just use %seen under a different name and w/o the @newlist. Further, count can be stored along w/ list index of each element in a n array reference to encfore input order.


In reply to Re: Rename Duplicate List Elements in an Array by parv
in thread Rename Duplicate List Elements in an Array by awohld

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.