Clear questions and runnable code
get the best and fastest answer
Yet more While issuesby Dandello (Beadle)
|on Mar 16, 2011 at 19:11 UTC||Need Help??|
Dandello has asked for the
wisdom of the Perl Monks concerning the following question:
Well, sort of
I'm trying to speed up a subroutine by going from this
Which gets - for obvious reasons - REALLY slow on large strings, to something like this:
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.
For both these, $x and $y are 2d array references, $z is a predetermined random number and $zazb is a string containing a more or less random number of 'a's, 'c's, 'y's and 'x's (and may be over than 25,000 characters long). This subroutine is supposed to locate one of the 'c's in $zazb, (without iterating over the entire string repeatedly) grab its mate from the @aob array (which is a number) and determine the value of $aob[$x][$y] based on the value of 'c's mate.
is adapted from http://www.perlmonks.org/?node_id=891330
Despite ikegami's input, I still can't get anything even closely related to the above code to work for this instance. However, since the parameters of the model data has changed, it's no longer an issue as all the indexes for 'c' need to saved to a file for data-munging.
So, this does a good and fast job finding the indices for 'c' from @aod (the array of strings containing 'c'.)
then for the random indexes ($off is the array of 'c' indices.)
then to get the random offset
It may not be pretty - but it does work.