in reply to Array of arrays used within object
You ask for a way to "relate a different @nreg to a particular sequence name". This might be done by turning @nreg from an array into a hash of arrays, where the hash key is the sequence name.sub addregion { my ($start,$end,$nreg) = @_; : for ($k=0;$k<@$nreg;$k++) :
My primary suggestion would be to try simplify the subroutine so that you pass in all parameters that it uses to operate. This reduces the external interactions and side effects and makes the entire code base simpler to deal with when you have to make changes.sub addregion { my ($start,$end,$sequence) = @_; : for ($k=0;$k<@{$nreg{$sequence}};$k++) : $tempcoding += $nreg{$sequence}[$k][1] - $nreg{$sequence}[$k][0] + 1;
It's a bit difficult to offer suggestions without seeing the use of nreg in the rest of the code, and the "bless" error doesn't seem to relate to any of the code presented so that confuses me. Is the code sample you presented the original code or the code after you have started the conversion?
Hmmm... After reading the post again, I'm wondering if maybe @nreg has one entry per sequence already, and you're trying to invert the structure of the data to have each sequence be a top leve object with the sub-array of @nreg[$k] be stored in the object.
|
|---|