in reply to out of memory problem
while(<>){ if (/^#+/){NEXT;} else{ chomp; @data=split (/\s+/,$_); $a=$data[0]; $b=$data[3]; $c=$data[4]; $d=$data[5]; $row{$a}{$b}{$c}=$d; } } print "Fished establishing hashs.\n";
I personally believe that your code exhibits several problems which may be or not be related to your memory usage one. (The latter may also lie outside of this code snippet.) First of all, it may be strict safe but at all effects seems not to: thus the first and best recommendation I can give you is to make it so!
Your code is also horribly and painstakingly indented, and other details suggest it may be retyped: in which case... don't! Paste it instead! One of the details is NEXT (note the capitalization!) which may actually be a sub of yours, but rather appears as a typo for next. If it is, then you don't need the else clause: that's precisely what next is about!
Then, your split is very close to an argumentless one, which is "optimized" to do what one generally wants to, I know it may not be your case, but I suspect it is.
Coming closer to your actual problem, do you really need a three level HoH? That creates quite a lot of references, so you may want to concoct up a single key suitably joining the keys you have now, if possible: perl even does this for you with an old (but perfectly working!) mechanism of pseudo multilevel hashes. All in all, your code may be transformed into:
my %row; while(<>){ next if /^#/; # if there's "one or more" then there's one! chomp; my @data=split; $row{ @data[0,3,4] }=$data[5]; }
|
|---|