Hi monks!

I am having a problem with my OOP data structure! Basically, I have an array that holds arrays of data. This data is just 1's and 0's.
Like This:
-----------
array cell 0 = (1,0,0,0,1,1,0)
array cell 1 = (0,0,0,1,1,1,1,0,0,1,1,1)
array cell 2 = (1,1,0,1,1,1,1,0,0,1,1,1)
etc...

My constructor looks something like this:

sub new { my ($class) = @_; my $self = { _length => "", _score => [ [],[] ], _coordinates => [], }; bless {$self,$class}; } # END "new" method

What I need to do is go through each data array in my @{$self->_score}[] array and output a comma-delimited list of coordinates whenever a string of 1's is encountered...

Like this:
if @{$self->_score}index = (1,1,1,0,0,1,1,0)
then i want
@($self->_coordinates}index = "0-2,5-6"

Easy Right?

But why can't I just do this:

sub findcoordinates { my ($self) = @_; my $first; my $last; for (my $i=2;$i <= 5;$i++) { my $base = 0; while($base <= (($self->{_length})-$i)) { if (@{$self->{_score}[$i][$base]} = "1") { $first = $base; while (@{$self->{_score}[$i][$base]} ne "0") { $last = $base; $base++; } @{$self->{_coordinates}[$base] = @{$self->{_coordin +ates}[$base] + "$first-$last"; } else { $base++; } } } } #END findcoordinates method

What this all means is that IF the Data cell = '1', continue to move down the array until the data cell isn't equal to '1' anymore. Then print out the first cell # and the last one parsed like this: "3-5" or something.
Problem is I always get a Can't use undefined value as an array reference error? Why do i get this error? Any suggestions as to a better way to accomplish my monk-ish task?


In reply to Parsing and scoring an Array of Arrays by mr_dont

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.