in reply to foreach to for

Word of advice, pick "for" or "foreach" and use one. Minor nit, but they're interchangable, and switching back and forth tends to make it less readable for me.

And just a quick note:

for( my $i=1; $i<@aas; $i++){ #etc }
can be written more perlish as (assuming you really want elements 0 .. $#aas of @aas, instead of 1..$#aas+1):
for( @aas ){ @codons = @{$Deg_codons{$_}}; for my $seq( keys %SEQ ){ for my $codon( @codons ){ $SEQ{$seq.$codon}=1; } delete $SEQ{$seq}; } }

There are probably some other changes that could be made here, but these are just the ones that jump off the page at me.



--chargrill
$,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}

Replies are listed 'Best First'.
Re^2: foreach to for
by bart (Canon) on Jun 19, 2006 at 06:42 UTC
    Word of advice, pick "for" or "foreach" and use one. Minor nit, but they're interchangable, and switching back and forth tends to make it less readable for me.
    Well, for me, I tend to use for for C-style loops (your first example) and foreach for the aliasing loops (your second example).

    I do believe a lot of people adhere to the same concept.

      And, for yet another way to do it, I follow the same pattern of for for indexing and foreach for aliasing, but I build indexing loops as
      for my $i (0..$#arr) { do_whatever(); }
      instead of doing it C-style (unless I need a more complex index transition than the usual $i++).