use strict; use warnings; use Test::More tests => 5; my @x = 1 .. 5; is_deeply([p( 3, 'x', @x)], [ @x ]); is_deeply([p(-3, 'x', @x)], [ @x ]); is_deeply([p( 7, 'x', @x)], [ @x, 'x', 'x' ]); is_deeply([p(-7, 'x', @x)], [ 'x', 'x', @x ]); @x = (); is_deeply([p(-4, 'x', @x)], [ 'x', 'x', 'x', 'x' ]); sub p {($a,$b,@x)=@_;@_=($b)x(abs@x-abs$a);@_=abs$a>@x?$a<0?(@_,@x):(@x,@_):@x}