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

Re: Nested loops?

by zakame (Pilgrim)
on Aug 23, 2017 at 17:24 UTC ( #1197881=note: print w/replies, xml ) Need Help??


in reply to Nested loops?

I only skimmed through this, but for that first foreach, you should have something %seen in place just before entering the loop, so it takes id/sequence as a key to skip alternates in the loop (next if %seen{$sequence}.)

Also, I'm probably wrong, but the way you describe your process sounds like a gather/take from Perl6. Here's some Perl5-ish implementation using Syntax::Keyword::Gather:

use Syntax::Keyword::Gather; my @sequences = ( ... ); my @filters = ( ... ); my @primary_and_filtered = gather { my %seen; for my $seq (@sequences) { take $seq unless $seen{$seq}; take map { $_->($seq) } @filters; $seen{$seq}++; } };

Note that the @filters doesn't correspond to your described filters list of sequences, but rather, a list of filter functions (e.g. another permute, or a more specific search, etc.) to evaluate your original primary sequence against.

Replies are listed 'Best First'.
Re^2: Nested loops?
by Speed_Freak (Sexton) on Aug 30, 2017 at 18:53 UTC

    Thanks for the response! I was looking into how %seen works and realized where my code was wrong

    I added a line above the loop: my %table2a = keys %table2 and then changed my if statement: if (exists ($table2a {$x}))

    Now it's working just as expected. You'll also notice that the parentheses in the if statement changed as well.

      Happy it helped :) Enjoy PerlMonks!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2019-06-25 17:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (107 votes). Check out past polls.

    Notices?