Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Nested loops?

by kcott (Archbishop)
on Aug 18, 2017 at 08:09 UTC ( [id://1197596]=note: print w/replies, xml ) Need Help??


in reply to Nested loops?

G'day Speed_Freak,

Firstly, there's all sorts of problems with your post:

  • No sample input data.
  • No expected output.
  • Incomplete code: it won't run; we can't test.
  • Use of identically named variables for different things, e.g. $sql1.
  • Declaration and initialisation of variables that are not subsequently used, e.g. @bases.

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-24 18:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found