line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Array::Average; |
2
|
1
|
|
|
1
|
|
32858
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
4
|
use Scalar::Util qw{reftype}; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
170
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION='0.02'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
BEGIN { |
9
|
1
|
|
|
1
|
|
5
|
use Exporter (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
10
|
1
|
|
|
1
|
|
6
|
use vars qw(@ISA @EXPORT); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
86
|
|
11
|
1
|
|
|
1
|
|
16
|
@ISA = qw(Exporter); |
12
|
1
|
|
|
|
|
268
|
@EXPORT = qw(average); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Array::Average - Calculates the average of the values passed to the function. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Array::Average; |
22
|
|
|
|
|
|
|
print average(4,5,6); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Array::Average is an L which exports exactly one function called average. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 USAGE |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use Array::Average; |
31
|
|
|
|
|
|
|
print average(4,5,6); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use Array::Average qw{}; |
34
|
|
|
|
|
|
|
print Array::Average::average(4,5,6); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 FUNCTIONS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 average |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Returns the average of all defined scalars and objects which overload "+". |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $average=average(1,2,3); |
43
|
|
|
|
|
|
|
my $average=average([1,2,3]); |
44
|
|
|
|
|
|
|
my $average=average({a=>1,b=>2,c=>3}); #only values not keys |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub average { |
49
|
27
|
|
|
27
|
1
|
61
|
my @data=_flatten(@_); |
50
|
27
|
100
|
|
|
|
51
|
if (@data) { |
51
|
24
|
|
|
|
|
23
|
my $sum=0; |
52
|
24
|
|
|
|
|
81
|
$sum+=$_ foreach @data; |
53
|
24
|
|
|
|
|
116
|
return $sum/scalar(@data); |
54
|
|
|
|
|
|
|
} else { |
55
|
3
|
|
|
|
|
12
|
return undef; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _flatten { |
59
|
187
|
100
|
|
187
|
|
360
|
if (@_ == 0) { |
|
|
100
|
|
|
|
|
|
60
|
2
|
|
|
|
|
4
|
return @_; |
61
|
|
|
|
|
|
|
} elsif (@_ == 1) { |
62
|
119
|
|
|
|
|
106
|
my $val=shift; |
63
|
119
|
100
|
|
|
|
354
|
if (!defined $val) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
64
|
2
|
|
|
|
|
6
|
return (); |
65
|
|
|
|
|
|
|
} elsif (!defined reftype($val)) { |
66
|
89
|
|
|
|
|
200
|
return $val; |
67
|
|
|
|
|
|
|
} elsif (reftype($val) eq "HASH") { |
68
|
7
|
|
|
|
|
8
|
return _flatten(values %{$val}); |
|
7
|
|
|
|
|
23
|
|
69
|
|
|
|
|
|
|
} elsif (reftype($val) eq "ARRAY") { |
70
|
11
|
|
|
|
|
11
|
return _flatten(@{$val}); |
|
11
|
|
|
|
|
24
|
|
71
|
|
|
|
|
|
|
} elsif (reftype($val) eq "SCALAR") { |
72
|
10
|
|
|
|
|
11
|
return _flatten(${$val}); |
|
10
|
|
|
|
|
21
|
|
73
|
|
|
|
|
|
|
} else { |
74
|
0
|
|
|
|
|
0
|
return $val; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} else { |
77
|
66
|
|
|
|
|
100
|
return _flatten(shift), _flatten(@_); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 BUGS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Please log on RT and send an email to the author. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SUPPORT |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
DavisNetworks.com supports all Perl applications including this package. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 AUTHOR |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Michael R. Davis |
93
|
|
|
|
|
|
|
CPAN ID: MRDVT |
94
|
|
|
|
|
|
|
Satellite Tracking of People, LLC |
95
|
|
|
|
|
|
|
mdavis@stopllc.com |
96
|
|
|
|
|
|
|
http://www.stopllc.com/ |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 COPYRIGHT |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This program is free software licensed under the... |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
The BSD License |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
The full text of the license can be found in the LICENSE file included with this module. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 SEE ALSO |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
L |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |