in reply to Uninitialized value in division and Illegal division by zero fix
Not addressing your problem but you might be able to save some typing and avoid mistakes by building your @array programmatically. The following code uses a recursive subroutine to construct an anonymous array ($raTerms), which is then dereferenced (@$raTerms) and printed. Running it with a maximum of three letters for brevity here.
use strict; use warnings; use 5.014; my $raItems = [ qw{ A T G C } ]; my $raTerms = []; makeCombos( $raTerms, 3, $raItems ); say for @$raTerms; sub makeCombos { my( $raTerms, $iters, $raItems, @terms ) = @_; my @localTerms; if ( @terms ) { push @localTerms, map { my $item = $_; map { $_ . $item } @terms } @$raItems; } else { push @localTerms, @$raItems; } $iters --; push @$raTerms, @localTerms; return $iters ? makeCombos( $raTerms, $iters, $raItems, @localTerms ) : (); }
The output.
A T G C AA TA GA CA AT TT GT CT AG TG GG CG AC TC GC CC AAA TAA GAA CAA ATA TTA GTA CTA AGA TGA GGA CGA ACA TCA GCA CCA AAT TAT GAT CAT ATT TTT GTT CTT AGT TGT GGT CGT ACT TCT GCT CCT AAG TAG GAG CAG ATG TTG GTG CTG AGG TGG GGG CGG ACG TCG GCG CCG AAC TAC GAC CAC ATC TTC GTC CTC AGC TGC GGC CGC ACC TCC GCC CCC
I hope this is helpful.
Cheers,
JohnGG
|
|---|