DanielM0412 has asked for the wisdom of the Perl Monks concerning the following question:
Sorry if this seems like a stupid question, youll be gettin a lot of these from me :) , as im 14 and on an internship, but anyways i wrote a function to read in a 4by4 matrix, and split it (for future use), but my question is how do i do the alter my code to make it able to read in a matrix with unknown dimensions H and K, heres my very limited code below
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $filepath = "OP.txt"; my $olddata = readdt2($filepath); print Dumper($olddata); sub readdt2 { my $ifn = shift; open(my $IFH, "<$ifn") or die "cannot open file $ifn\n"; my $line; my @nt = ("A","C","G","T"); my %ret; my @tmp; for my $j(@nt) { $ret{$j} = []; $line = <$IFH>; chomp($line); @tmp = split(/\s+/,$line); for (my $i=0; $i<=$#tmp; $i++ ) { $ret{$j}[$i]= $tmp[$i] ; } } close($IFH); return(\%ret); }
All advice much appreciated, thanks for your time and patience
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to make this code more flexible
by Sandy (Curate) on Jul 21, 2011 at 17:05 UTC | |
by DanielM0412 (Acolyte) on Jul 21, 2011 at 21:14 UTC | |
by Sandy (Curate) on Jul 21, 2011 at 22:11 UTC | |
by DanielM0412 (Acolyte) on Jul 25, 2011 at 14:07 UTC | |
by Sandy (Curate) on Jul 25, 2011 at 17:49 UTC | |
| |
|
Re: How to make this code more flexible
by Marshall (Canon) on Jul 21, 2011 at 22:44 UTC |