$sz ||= 3; # user parameter $top = $sz - 1; @next = ( 1 .. $top, 0 ); $tl = $top; @a = (); # . . . $a[ $tl = $next[$tl] ] = $val; # 'push' zero or more times # . . . @all = @a[ $tl + 1 .. $#a, 0 .. $tl ]; $tl = $top; @a = ();
In reply to Circular buffer instead of shift/push by petral
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |