in reply to Punnett squares and perl.

Well, the first thing I'd want to do is allow all the input to come from a named file -- or if I choose to type, make it easier/quicker to enter values. Nothing strikes me as more tedious or error-prone than typing a bunch of values, one per line, in response to prompt strings while a program is running. So:
#!/usr/bin/perl -w use strict; my $Usage = <<ENDUSE; Usage: $0 [punnett_square_specs.file] input data should contain two rows of values: first row lists pairs for the top of the punnett square second row lists pairs for the side of the punnett square ENDUSE die $Usage if(@ARGV and ! -r $ARGV[0]); my @top = split /\s+/, <>; my @side = split /\s+/, <>; for my $t ( @top ) { for my $s ( @side ) { print "$t$s\n"; } }
I'm just taking it for granted that this really is the output format that you want (two values per line, number of lines = scalar @top * scalar @side). Prompting for $numtop and $numSide seems unnecessary -- just count up how many space-separated tokens are provided for each set.

As I've written it here, you can still type in the values after you start the program (or paste in lines of values from some other window); but you can also save your values in a file, and have it read that file, or you may have some other process that outputs the two lines of values, and pipe it to the script.

update: If, as suggested by BrowserUK's reply, you really want to print out something that looks like a square (i.e. a table) rather than just a list of lines (the way the OP code was written), then I'd change my loop to look like this (taking the terms "top" and "side" literally here):

print join( " ", " ", @top, $/); for my $s ( @side ) { print "$s "; for my $t ( @top ) { print " $t$s"; } print $/; }
Given two lines of input like:
gg hh kk jj 11 22 33 44
That loop will produce:
gg hh kk jj 11 gg11 hh11 kk11 jj11 22 gg22 hh22 kk22 jj22 33 gg33 hh33 kk33 jj33 44 gg44 hh44 kk44 jj44

Replies are listed 'Best First'.
Re^2: Punnett squares and perl.
by belg4mit (Prior) on Dec 01, 2006 at 07:45 UTC
    Now you just need to handle the relative frequencies of each allele and genotype ;-)

    --
    In Bob We Trust, All Others Bring Data.