in reply to Yet more While issues
For clarity more than for speed,
should bemy $offset = splice @cPosns, rand @cPosns, 1;
andmy $offset = $cPosns[rand @cPosns];
should simply bewhile (1) { ... last; }
...
For speed, don't copy the zazb argument into a local variable. Access $_[3] directly.
A possible tweak:
push @cPosns, pos $zazb while $zazb =~ m{(?=c)}g;
might be faster as
push @cPosns, $-[0] while $zazb =~ m{c}g;
or maybe even
my $pos = -1; push @cPosns, $pos while ($pos = index($zazb, 'c', $pos+1)) >= 0;
Benchmark and find out.
Which I just can't seem to get my head around to get it to work without throwing 'undefined value' warnings all over the place.
This will occur when 'c' doesn't occur in $zazb. Based on your first snippet, you want
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]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Yet more While issues
by Dandello (Monk) on Mar 16, 2011 at 22:04 UTC | |
by ikegami (Patriarch) on Mar 16, 2011 at 22:38 UTC | |
by Dandello (Monk) on Mar 17, 2011 at 19:48 UTC | |
|
Re^2: Yet more While issues
by Dandello (Monk) on Mar 18, 2011 at 05:20 UTC | |
by ikegami (Patriarch) on Mar 18, 2011 at 07:23 UTC |