in reply to trouble understanding boss's code
Well, he does return a reference to that hash at the end, so that part makes sense.
Comment1: The shift at the beginning is implicitly shifting off of @_ to pull the first parameter to the function into $ifn. The open would be better written as: open my $IFH, '<', $ifn or die "Cannot open file '$ifn': reason = $!\n"; so that you can see WHY it failed to open via the $!.
Comment2: Initializing $ret{A} through $ret{T} to be new arrayrefs as they come up in the loop. The loop would be better written as for my $j (@nucleotides) {...}, and then use $j in place of $nucleotides[$j]
Comment3: The -> is redundant. But it seems to me the whole darn $i loop is redundant too. It could be more simply written as $ret{$nucleotides[$j]} = split(/\s+/, $line); (note the comment 2 replacement could simplify the $j here too). My guess for this one is that the Boss is thinking C, and is doing a manual memcpy().
Putting the first line of the file into $ret{A} and the fourth line into $ret{T} seems very odd, but I've no idea what the later use is, so maybe it makes sense.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: trouble understanding boss's code
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 | |
|
Re^2: trouble understanding boss's code
by Anonymous Monk on Jul 21, 2011 at 11:27 UTC |