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

In reply to Re: Punnett squares and perl. by graff
in thread Punnett squares and perl. by DigitalKitty

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.