in reply to Obtaining combinations of hash keys and values
#!/usr/bin/perl use warnings; use strict; my %fragments = ( 1 => { F => 'TTAAGTAGCATCGATTTATAGCATCGACTAGTAA', R => 'TTACTAGTCGATGCTATAAATCGATGCTACTTAA', }, 2 => { F => 'TTAGCTACGATCAGCTACGATCGAGCGACTACGTAGCAA +', R => 'TTGCTACGTAGTCGCTCGATCGTAGCTGATCGTAGCTAA +', }, ); my %combinations; for my $fragment (keys %fragments) { for my $other_fragment (keys %fragments) { next if $fragment eq $other_fragment; for my $cognate (qw( F R )) { for my $other_cognate (qw( F R )) { $combinations{"$fragment$cognate$other_fragment$other_ +cognate"} = $fragments{$fragment}{$cognate} . $fragments{$other_fragment}{$other_cognate}; } } } } use Data::Dumper; print Dumper(\%combinations);
This generates 8 entries, not four, as it creates 2F1F etc., too. You can modify the "next" condition to avoid it, i.e.
next if $fragment ge $other_fragment;
If you need to combine N fragments, see Algorithm::Loops.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Obtaining combinations of hash keys and values
by Anonymous Monk on Apr 29, 2016 at 09:01 UTC | |
by Cristoforo (Curate) on Apr 29, 2016 at 18:40 UTC | |
|
Re^2: Obtaining combinations of hash keys and values
by Anonymous Monk on Apr 29, 2016 at 09:13 UTC | |
by choroba (Cardinal) on Apr 29, 2016 at 09:26 UTC |