in reply to alternating row colors
Then the current color is always the first element.push @colors, shift @colors;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re2: alternating row colors
by tye (Sage) on May 18, 2001 at 01:55 UTC | |
That one is interesting to watch behind the scenes. You start out with a simple array. Each time you rotate it either 1) There is some spare room in the space allocated for the array and an item is moved into that space and Perl notes that the real array is really further down in that block of space than it used to be or 2) There isn't any space left in which case a larger space is allocated for the array and the array is placed at the front of that new bigger space.
So the "offset" to finding the first entry will progress
something like (from a real run using Devel::Peek): while the space for the array slowly grows without bound (it appears). Update: Sounds like I stopped experimenting just a bit too soon. Good thing I covered my butt with that "it appears" on the end. (: - tye (but my friends call me "Tye") | [reply] |
by tilly (Archbishop) on May 18, 2001 at 05:38 UTC | |
The line to look for is "ARRAY =..." When there is an offset it will say "(offset=2)". I find it goes 0, 1, 2, then back to 0, then up to 10, back to zero, up to 10, and so on. Now if I try it with an array of 3 elements it goes up to 1, 0-9, 0-25, 0-25, 0-25... With 4 the same thing only it goes up to 24. Etc. If anyone wants to play with this, here is an easy script to hack around with. Play with the array size and run it as many times as you want...
| [reply] [d/l] [select] |
by jeroenes (Priest) on May 18, 2001 at 20:00 UTC | |
That's clear: a jump at every 2**(1..$n) length of the array. The jump is to 3 times the array_length at the jump. So now we can deduct the perl source code from this {grin}. There are small deviations due to the poor representation of lines on the ASCII field. For smaller array lengths, this relation does not hold. Jeroen | [reply] [d/l] |