File: stat_mean.pm

package info (click to toggle)
libcatmandu-stat-perl 0.13-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,048 kB
  • sloc: perl: 375; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 521 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package Catmandu::Fix::stat_mean;

use Catmandu::Sane;
use Moo;
use Catmandu::Fix::Has;
use Statistics::Basic;

has path => (fix_arg => 1);

with 'Catmandu::Fix::SimpleGetValue';

sub emit_value {
    my ($self, $var) = @_;
    "${var} = Statistics::Basic::mean(${var}) if is_array_ref(${var});";
}

=head1 NAME

Catmandu::Fix::stat_mean - calculate the mean of an array

=head1 SYNOPSIS

   # Calculate the mean of foo. E.g. foo => [1,2,3,4]
   stat_mean(foo)  # foo => '2.5'

=head1 SEE ALSO

L<Catmandu::Fix>

=cut

1;