Back to square one I guess. This
only seems to work relatively short strings, but not when the string gets much more than 500 characters. Then it throws 'uninitialized value in $offset' errors which I'm guessing means the algorithm didn't find the one 'c' that had to be there.sub popnum3 { my ( $x, $y, $z ) = @_; # $_[3] is $zazb if ( $y == 0 ) { $aob[$x][0] = $initial * ( 1 + $z ); } else { my @cPosns; push @cPosns, $-[0] while $_[3] =~ m{c}g; if (@cPosns) { my $offset = $cPosns[rand @cPosns]; $aob[$x][$y] = $aob[$offset][ $y - 1 ] * ( 1 + $z ); } } return $aob[$x][$y]; }
I admit I'm at my wit's end here. This looks like it should work, but it doesn't. There is a 'c' in every row, so that's not the problem.
THIS works
But takes about 5 seconds per row on the full array and since there's 8400 rows in the full run, that's about 12 hours.sub popnum3 { my ( $x, $y, $z, $zazb ) = @_; if ( $y == 0 ) { $aob[$x][0] = $initial * ( 1 + $z ); } else { while (1) { my $xda = int rand( $total + 1 ); if ( substr( $zazb, $xda, 1 ) eq 'c' ) { $aob[$x][$y] = $aob[$xda][ $y - 1 ] * ( 1 + $z ); last; } } } return $aob[$x][$y]; }
Getting the run time down would be very helpful.
Thanks
In reply to Re^2: Yet more While issues
by Dandello
in thread Yet more While issues
by Dandello
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |