DanielM0412 has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: trouble understanding boss's code
by Util (Priest) on Jul 20, 2011 at 17:16 UTC | |
by DanielM0412 (Acolyte) on Jul 20, 2011 at 18:01 UTC | |
|
Re: trouble understanding boss's code
by SuicideJunkie (Vicar) on Jul 20, 2011 at 17:27 UTC | |
by DanielM0412 (Acolyte) on Jul 20, 2011 at 18:39 UTC | |
by SuicideJunkie (Vicar) on Jul 20, 2011 at 18:51 UTC | |
by DanielM0412 (Acolyte) on Jul 20, 2011 at 19:04 UTC | |
by DanielM0412 (Acolyte) on Jul 20, 2011 at 19:11 UTC | |
by Anonymous Monk on Jul 21, 2011 at 11:27 UTC | |
|
Re: trouble understanding boss's code
by runrig (Abbot) on Jul 20, 2011 at 17:18 UTC |