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.#!/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"; } }
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):
Given two lines of input like:print join( " ", " ", @top, $/); for my $s ( @side ) { print "$s "; for my $t ( @top ) { print " $t$s"; } print $/; }
That loop will produce:gg hh kk jj 11 22 33 44
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |