On Jan 21, 2008 4:30 PM, Kevin Viel <[EMAIL PROTECTED]> wrote: snip > You placed another little gem in here for me to digest: > > > $outer{$snp}{$_}++ for $genotype =~ /(.)/g; } > > I guess when I conceive of that by myself, I should move to the intermediate > mailing list :) snip
It could also have been $outer{$snp}{$_}++ for split //, $genotype; I am not sure which one I prefer. The split is a little bit easier to understand at first glance, but the regex is a more flexible (e.g. if the data was in the form AABB and you wanted AA, BB instead of A,A,B,B). The substr function (while useful) is often the wrong choice in Perl; especially if you are calling it more than once. Multiple calls to the same function in Perl scream out for iteration and a list producing variant of the function call. For the substr function the common list producing functions are split*, unpack**, and regexes***. You also know it is time to take a look at iteration when you find yourself naming variables $var1, $var2, etc. This is a sure sign that you are doing work that Perl should be doing for you, or you have no imagination in variable naming (which is a different sort of problem). * if you have discrete fields separated by a fixed string or pattern ** if you have a fixed width record format *** the above cases and more -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/