Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Yet more While issues

by Dandello (Scribe)
on Mar 18, 2011 at 05:20 UTC ( #893910=note: print w/ replies, xml ) Need Help??


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

Back to square one I guess. This

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]; }
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.

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

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]; }
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.

Getting the run time down would be very helpful.

Thanks


Comment on Re^2: Yet more While issues
Select or Download Code
Re^3: Yet more While issues
by ikegami (Pope) on Mar 18, 2011 at 07:23 UTC

    Then it throws 'uninitialized value in $offset' errors

    I don't believe you when you say that snippet produced that warning.

    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.

    No. If it doesn't find any 'c', it never uses $offset.

    PS - Don't count out half the warning (not even counting the line number).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (17)
As of 2014-07-24 21:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls