Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Yet more While issues

by Dandello (Scribe)
on Mar 16, 2011 at 22:04 UTC ( #893649=note: print w/ replies, xml ) Need Help??


in reply to Re: Yet more While issues
in thread Yet more While issues

I got it - at least it's stopped throwing warnings and it's a whole lot faster that what I had before.

Since popnum3 is called from inside an if/else

else { my $pos = -1; push @cPosns, $pos while ($pos = index($zazb, 'c', $pos+1)) >= 0; my $offset = $cPosns[rand @cPosns]; $cell = sprintf '%.2f', popnum3( $x, $y, $copycop, $offset, ); }
then
sub popnum3 { my ( $x, $y, $z, $offset ) = @_; if ( $y == 0 ) { $aob[$x][0] = $initial * ( 1 + $z ); } else { while (1) { $aob[$x][$y] = $aob[$offset][ $y - 1 ] * ( 1 + $z ); last; } } return $aob[$x][$y]; }

So far it's looking good. Thanks


Comment on Re^2: Yet more While issues
Select or Download Code
Re^3: Yet more While issues
by ikegami (Pope) on Mar 16, 2011 at 22:38 UTC
    What's with the useless while(1) { ...; last; } again?

      Habit

      I'm still trying to get everything configured to work right - When I have the code set up like this:

      else { my $pos = -1; push @cPosns, $pos while ($pos = index($zazb, 'c', $pos+1)) >= 0; my $offset = $cPosns[rand @cPosns]; $cell = sprintf '%.2f', popnum3( $x, $y, $copycop, $offset, ); }
      then
      sub popnum3 { my ( $x, $y, $z, $offset ) = @_; if ( $y == 0 ) { $aob[$x][0] = $initial * ( 1 + $z ); } else { while (1) { $aob[$x][$y] = $aob[$offset][ $y - 1 ] * ( 1 + $z ); last; } } return $aob[$x][$y]; }
      It's reiterating over the entire string for every single 'a' or 'c' which starts fast then slows to a crawl

      When I move this section

      my $pos = -1; push @cPosns, $pos while ($pos = index($zazb, 'c', $pos+1)) >= 0;
      above all the if/else's, to just under where $zazb is defined, then the $offset variable in
      else { my $offset = $cPosns[rand @cPosns]; $cell = sprintf '%.2f', popnum3( $x, $y, $copycop, $offset, ); }
      becomes undefined when imported into popnum3.

      So obviously I'm still missing something.

      There is always at least 1 'c' in the string so that's not the problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://893649]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2014-10-25 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (142 votes), past polls