in reply to Nested loops?
G'day Speed_Freak,
Firstly, there's all sorts of problems with your post:
Your follow-up response suffers from much the same problems. Please read "How do I post a question effectively?". Aim to provide us with an SSCCE.
In general, you should just create a single hash from the smaller dataset (your seq2?); then iterate the larger dataset (your seq1?) processing this raw data based on the single hash created. The following code demonstrates the technique:
#!/usr/bin/env perl -l use strict; use warnings; my $all_aref = [ [qw{id1 seq1}], [qw{id2 seq2}], [qw{id3 seq4}] ]; my $filter_aref = [ [qw{id1 seq1}], [qw{id3 seq3}] ]; my %filter_hash; $filter_hash{$_->[0]}{$_->[1]} = 1 for @$filter_aref; for (@$all_aref) { if (exists $filter_hash{$_->[0]}) { print "ID $_->[0] in filter"; if (exists $filter_hash{$_->[0]}{$_->[1]}) { print "SEQ $_->[1] in filter for ID $_->[0]"; } else { print "SEQ $_->[1] not in filter for ID $_->[0]"; } } else { print "ID $_->[0] not in filter"; } }
Output:
ID id1 in filter SEQ seq1 in filter for ID id1 ID id2 not in filter ID id3 in filter SEQ seq4 not in filter for ID id3
Note that I strongly emphasised "demonstrates the technique" because this is not intended to be any sort of solution. Not knowing what the input looks like, how it should be processed, or what sort of output is required, a solution is not possible at this time!
— Ken
|
|---|