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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |