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++; }
In reply to Re: Circular buffer
by moritz
in thread Circular buffer
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |