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
In reply to How to make this code more flexible by DanielM0412
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |