I'm not sure if you can get a more compact solution than @DVK.
use strict; use warnings;
use List::Util qw(sum);
my @array = (3, 2, 1, 5);
my $sum = sum @array;
for my $x ( @array ) {
print $sum, "\n";
$sum -= $x;
}
print "0\n";
Combining sumwith map:
use strict; use warnings;
use List::Util qw(sum);
my @array = (3, 2, 1, 5);
my $sum = sum @array;
print join("\n", map $sum -= $_, (0, @array)), "\n";
source
share