I think the best way to do this is, "USE A HASH":
#!/usr/bin/perl
use strict;
use warnings;
my @labels = ('1', '1', '1', '2', '3', '4', '5', '6', '6', '7');
my @seqs = ('a', 'ctgc', 'tggattgactgtg', 'atgcatg' ,
'ctgctgcatgtgatgactgtg', 'tgatg', 'gtgt',
'gcgccggactatgattgagctagcgtatgctgcatgctgat',
'gggtttttttttttccccccccccc', 'aaaaaagggggg');
# a useful rule of thumb to remember when programming in Perl:
# can I use a hash to solve this problem?
my %output = ();
if (@labels != @seqs)
{
die "arrays are different length";
}
for (my $i = 0; $i <= $#labels; $i++)
{
# concatenate the sequence onto what's already there for this labe
+l
$output{$labels[$i]} .= $seqs[$i];
}
foreach my $label (sort keys %output)
{
print "label: $label = $output{$label}\n";
}
__END__
Output:
label: 1 = actgctggattgactgtg
label: 2 = atgcatg
label: 3 = ctgctgcatgtgatgactgtg
label: 4 = tgatg
label: 5 = gtgt
label: 6 = gcgccggactatgattgagctagcgtatgctgcatgctgatgggtttttttttttcccc
+ccccccc
label: 7 = aaaaaagggggg