1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/local/bin/perl use strict; use warnings; use feature qw(say); use Test::More; my @TESTS = ( [ [1,0,3,0,0,5], '1 3 5 0 0 0' ], [ [1,6,4], '1 6 4' ], [ [0,1,0,2,0], '1 2 0 0 0' ], [ [(0,1) x 100 ], "@{[ (1)x 100, (0)x 100 ]}" ], ); is( "@{[ move_zero(@{$_->[0]}) ]}", $_->[1] ) for @TESTS; done_testing(); sub move_zero{grep({$_}@_),grep{!$_}@_}