# ------------------------------------------------- # subroutine to read a generic 2d array from a file # ------------------------------------------------- sub readdt2 { # get the name of the file to read my $ifn = shift; # open the file (note that it is commented out for now for testing) # open(my $IFH, "<$ifn") or die "cannot open file $ifn\n"; my @ret; # keep track of row number my $i = 0; # read from your file # (for testing purpose, read data following the __DATA__ statement below) while (my $line = ) { # take your line from your data file, and split into an array, using spaces as your deliminator my @tmp = split(/\s+/,$line); # set the i(th) row to the array from your file $ret[$i] = \@tmp; # increment the row number $i++; } # return your array of arrays (i.e. a 2-d array) return(\@ret); } __DATA__ 11 12 13 14 15 16 17 21 22 23 24 25 26 27 31 32 33 34 35 36 37 41 42 43 44 45 46 47 51 52 53 54 55 56 57 61 62 63 64 65 66 67