"Is hashes the way to go?"

Your choice of data structure will depend on a number of factors, such as how you want to store and retrieve the structure, how you want to access the data in the structure, and so on. Have a read of "Perl Data Structures Cookbook" to get an idea of what's available.

Here's one possible way:

#!/usr/bin/env perl use strict; use warnings; my %data; { local $/ = "\n>"; while (<DATA>) { $_ = substr $_, 1 if $. == 1; my ($ids, $seq, $lab) = split /\n/; my ($id1, $id2) = split /[|]/, $ids; push @{$data{"$id2-$seq"}}, [$id1, $lab]; } } # For DEMO use Data::Dump; dd \%data; __DATA__ >4kt0_M|P72986 MALSDTQILAALVVALLPAFLAFRLSTELYK iiiiiiiiiMMMMMMMMMMMMMMMMMIIIII >6uzv_m|P72986 MALSDTQILAALVVALLPAFLAFRLSTELYK iiiiiiiiiiiiMMMMMMMMMMMMMMMMMII >5oy0_m|P72986 MALSDTQILAALVVALLPAFLAFRLSTELYK iiiiiiiiiMMMMMMMMMMMMMMMMMIIIII >6hqb_M|P72986 MALSDTQILAALVVALLPAFLAFRLSTELYK iiiiiiiiiiiMMMMMMMMMMMMMMIIIIII

Output:

{ "P72986-MALSDTQILAALVVALLPAFLAFRLSTELYK" => [ ["4kt0_M", "iiiiiiiiiMMMMMMMMMMMMMMMMMIIIII"], ["6uzv_m", "iiiiiiiiiiiiMMMMMMMMMMMMMMMMMII"], ["5oy0_m", "iiiiiiiiiMMMMMMMMMMMMMMMMMIIIII"], ["6hqb_M", "iiiiiiiiiiiMMMMMMMMMMMMMMIIIIII"], ], }

— Ken


In reply to Re: How to make unique entries by kcott
in thread How to make unique entries 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.