"Can you please advise what kind of structure I need to use?"

You can use simple hash (%uniq in code below); take advantage of the fact that hash keys are unique; and form those keys by joining string1 & string2 with a character that won't appear in either string (I used a tab; change that to something else if your strings can contain tabs).

#!/usr/bin/env perl use strict; use warnings; use constant { REC_SEP => "\n//\n", KEY_SEP => "\t", OUT_FMT => "%s\n%s\n%s\n//\n", }; my %uniq; { local $/ = REC_SEP; while (<DATA>) { chomp; my ($id, $s1, $s2) = split; $uniq{join KEY_SEP, $s1, $s2} = $id; } } printf OUT_FMT, $uniq{$_}, split(KEY_SEP) for keys %uniq; __DATA__ nick AAAAAAAAAA BBBBBBBBBB // george EGRGERHTETEHTHR VFRTTHTRRHTE // andreas AAAAAAAAAA BBBBBBBBBB // thomas EWTRYTUYJTHT CEWWEQRWT$G // peter EGRGERHTETEHTHR VFRTTHTRRHTE //

Output from sample run:

andreas AAAAAAAAAA BBBBBBBBBB // peter EGRGERHTETEHTHR VFRTTHTRRHTE // thomas EWTRYTUYJTHT CEWWEQRWT$G //

Note that hashes are unordered. Although the output shown may appear to be ordered, on a couple of other runs that I tested I got thomas/andreas/peter & thomas/peter/andreas (and with sufficient test runs, I would have got all possible orders). If the output order is important to you, just add some sorting; e.g.

... for sort { $uniq{$a} cmp $uniq{$b} } keys %uniq;

— Ken


In reply to Re: Make unique hash of arrays? by kcott
in thread Make unique hash of arrays? by Anonymous Monk

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.