this code is reading in a 4by4 matrix, ( related to biology ) here is the matrix
0.95 0.02 0.07 0.07 #A 0.03 0.01 0.06 0.83 #C 0.01 0.02 0.80 0.09 #G 0.01 0.95 0.07 0.01 #T
my $filepath = "OP.txt"; my $newdata = readdt2($filepath); sub readdt2 { my $ifn = shift; # how does this work open(my $IFH, "<$ifn") or die "cannot open file $ifn\n"; my $line; my @nucleotides = ("A","C","G","T"); my %ret; #why did he name a hash return?? that really confused me my @tmp; for(my $j=0;$j<4;$j++) { $ret{$nucleotides[$j]} = []; #dont understand $line = <$IFH>; chomp($line); @tmp = split(/\s+/,$line); for(my $i=0;$i<=$#tmp;$i++) { $ret{$nucleotides[$j]}->[$i]= $tmp[$i] ; #dont understand } } close($IFH); return(\%ret); }
what really threw me off was why did he name a hash $ret which is short for return thanks in advance! P.S. how can i make this code more flexible? say it reads in a matrix with unknown dimensions H, and K
In reply to trouble understanding boss's code by DanielM0412
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |