Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How to make unique entries

by kcott (Archbishop)
on Jun 02, 2023 at 07:58 UTC ( #11152598=note: print w/replies, xml ) Need Help??


in reply to How to make unique entries

"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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11152598]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2023-12-01 01:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?