Whilst attempting to convert some subroutines into module, I've run into difficulty with one particular feature. @nreg in the code below is used to store the start and end locations of features in a nucleotide sequence, so that another method may be used to determine whether a given base is within any of the defined regions.
sub addregion { my ($start,$end) = @_; if ($start > $end) { ($start,$end) = ($end,$start); } my $done = 0; my $k; my $tempcoding = 0; for ($k=0;$k<@nreg;$k++) { # calculate sum of bases $tempcoding += $nreg[$k][1] - $nreg[$k][0] + 1; # new region starts after old region ends next if ($nreg[$k][1] < $start); # new region ends before old region starts if ($end < $nreg[$k][0]) { splice(@nreg,$k,0,[$start,$end]); $done = 1; last; } # regions overlap $nreg[$k][0] = $start < $nreg[$k][0] ? $start : $nreg[$k][0]; $nreg[$k][1] = $end > $nreg[$k][1] ? $end : $nreg[$k][1]; $done = 1; # Combine two regions if the new section has brough about an o +verlap while ($k < $#nreg and $nreg[$k][1] > $nreg[$k+1][0]) { $nreg[$k][1] = $nreg[$k+1][1]; splice(@nreg,$k+1,1); } last; } unless ($done) { push @nreg,[$start,$end]; } }
Several (hundreds, even) sequences may be read, and it's apparently necessary to define a new object relating @nreg to the name of each sequence, as I find that the values for all sequences are pushed into the same array. Can anyone suggest a suitable way to set up a "new" method to relate a different @nreg to a particular sequence name, please? I've tried various permutations, which either use the same array every time or refuse to bless it (e.g. "Attempt to bless into a reference at..." messages appear). Thanks for any suggestions!

In reply to 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.