Logo

Programming-Idioms

History of Idiom 202 > diff from v5 to v6

Edit summary for version 6 by daxim:
New Perl implementation by user [daxim]

Version 5

2019-09-29, 06:24:24

Version 6

2019-09-29, 10:40:05

Idiom #202 Sum of squares

Calculate the sum of squares s of data, an array of floating point values.

Idiom #202 Sum of squares

Calculate the sum of squares s of data, an array of floating point values.

Imports
use List::Util qw(sum);
Code
my $s = sum map { $_ ** 2 } @data;
Doc URL
http://p3rl.org/List::Util#sum