in reply to Circular buffer
Just use an array, and a scalar to point into the array.
my @buffer = (0) x 5; my $pointer = 0; for (0..30) { print "old value: ", $buffer[$pointer % @buffer], "\n"; print "new value: $_\n"; $buffer[$pointer % @buffer] = $_; $pointer++; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Circular buffer
by mellon85 (Monk) on Mar 20, 2011 at 17:11 UTC | |
by moritz (Cardinal) on Mar 20, 2011 at 18:53 UTC | |
by repellent (Priest) on Mar 20, 2011 at 19:08 UTC |