I'm not sure I understand exactly what you mean by "convert subroutines into modules". It looks like one problem you have is the fact that the subroutine "addregion" is accessing the variable @nreg which has a scope wider than just the subroutine (e.g., a global variable). You might change the code to pass this array in, probably by reference.
sub addregion { my ($start,$end,$nreg) = @_; : for ($k=0;$k<@$nreg;$k++) :
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,$sequence) = @_; : for ($k=0;$k<@{$nreg{$sequence}};$k++) : $tempcoding += $nreg{$sequence}[$k][1] - $nreg{$sequence}[$k][0] + 1;
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.

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.


In reply to Re: Array of arrays used within object by esh
in thread Array of arrays used within object by knirirr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.